mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Properly propagate ObjectFlags.NonInferrableType, clean up non-inferrable code paths (#49887)
This commit is contained in:
29
tests/cases/compiler/nonInferrableTypePropagation1.ts
Normal file
29
tests/cases/compiler/nonInferrableTypePropagation1.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
// @strict: true
|
||||
|
||||
type Op<I, O> = (thing: Thing<I>) => Thing<O>;
|
||||
type Thing<T> = {
|
||||
value: T;
|
||||
pipe<A, B>(
|
||||
opA: Op<T, A>,
|
||||
opB: Op<A, B>,
|
||||
): Thing<B>;
|
||||
};
|
||||
type Box<V> = { data: V };
|
||||
|
||||
declare const thing: Thing<number>;
|
||||
|
||||
declare function map<T, R>(project: (value: T) => R): Op<T, R>;
|
||||
declare function tap<T>(next: (value: T) => void): Op<T, T>;
|
||||
declare function box<V>(data: V): Box<V>;
|
||||
declare function createAndUnbox<V>(factory: () => Thing<V | Box<V>>): Thing<V>;
|
||||
declare function log(value: any): void;
|
||||
|
||||
const result1 = createAndUnbox(() => thing.pipe(
|
||||
map((data) => box(data)),
|
||||
tap((v) => log(v)),
|
||||
));
|
||||
|
||||
const result2 = createAndUnbox(() => thing.pipe(
|
||||
tap((v) => log(v)),
|
||||
map((data) => box(data)),
|
||||
));
|
||||
33
tests/cases/compiler/nonInferrableTypePropagation2.ts
Normal file
33
tests/cases/compiler/nonInferrableTypePropagation2.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
// @strict: true
|
||||
|
||||
export interface Predicate<A> {
|
||||
(a: A): boolean
|
||||
}
|
||||
|
||||
interface Left<E> {
|
||||
readonly _tag: 'Left'
|
||||
readonly left: E
|
||||
}
|
||||
|
||||
interface Right<A> {
|
||||
readonly _tag: 'Right'
|
||||
readonly right: A
|
||||
}
|
||||
|
||||
type Either<E, A> = Left<E> | Right<A>;
|
||||
|
||||
interface Refinement<A, B extends A> {
|
||||
(a: A): a is B
|
||||
}
|
||||
|
||||
declare const filter: {
|
||||
<A, B extends A>(refinement: Refinement<A, B>): (as: ReadonlyArray<A>) => ReadonlyArray<B>
|
||||
<A>(predicate: Predicate<A>): <B extends A>(bs: ReadonlyArray<B>) => ReadonlyArray<B>
|
||||
<A>(predicate: Predicate<A>): (as: ReadonlyArray<A>) => ReadonlyArray<A>
|
||||
};
|
||||
|
||||
declare function pipe<A, B>(a: A, ab: (a: A) => B): B;
|
||||
declare function exists<A>(predicate: Predicate<A>): <E>(ma: Either<E, A>) => boolean;
|
||||
|
||||
declare const es: Either<string, number>[];
|
||||
const x = pipe(es, filter(exists((n) => n > 0)))
|
||||
Reference in New Issue
Block a user