Properly propagate ObjectFlags.NonInferrableType, clean up non-inferrable code paths (#49887)

This commit is contained in:
Jake Bailey
2022-07-14 18:33:09 -07:00
committed by GitHub
parent 4902860302
commit cf3af3febd
9 changed files with 637 additions and 39 deletions

View 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)),
));

View 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)))