Skip to content

Revert PR 61668 #62158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 77 additions & 37 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6540,7 +6540,7 @@ export const enum ObjectFlags {
CouldContainTypeVariablesComputed = 1 << 19, // CouldContainTypeVariables flag has been computed
/** @internal */
CouldContainTypeVariables = 1 << 20, // Type could contain a type variable
SingleSignatureType = 1 << 27, // A single signature type extracted from a potentially broader type

ClassOrInterface = Class | Interface,
/** @internal */
RequiresWidening = ContainsWideningType | ContainsObjectOrArrayLiteral,
Expand All @@ -6556,6 +6556,7 @@ export const enum ObjectFlags {
ContainsSpread = 1 << 21, // Object literal contains spread operation
ObjectRestType = 1 << 22, // Originates in object rest declaration
InstantiationExpressionType = 1 << 23, // Originates in instantiation expression
SingleSignatureType = 1 << 27, // A single signature type extracted from a potentially broader type
/** @internal */
IsClassInstanceClone = 1 << 24, // Type is a clone of a class instance type
// Flags that require TypeFlags.Object and ObjectFlags.Reference
Expand Down Expand Up @@ -6770,6 +6771,12 @@ export interface AnonymousType extends ObjectType {
instantiations?: Map<string, Type>; // Instantiations of generic type alias (undefined if non-generic)
}

/** @internal */
// A SingleSignatureType may have bespoke outer type parameters to handle free type variable inferences
export interface SingleSignatureType extends AnonymousType {
outerTypeParameters?: TypeParameter[];
}

/** @internal */
export interface InstantiationExpressionType extends AnonymousType {
node: NodeWithTypeArguments;
Expand Down Expand Up @@ -7055,6 +7062,8 @@ export interface Signature {
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
/** @internal */
instantiations?: Map<string, Signature>; // Generic signature instantiation cache
/** @internal */
implementationSignatureCache?: Signature; // Copy of the signature with fresh type parameters to use in checking the body of a potentially self-referential generic function (deferred)
}

export const enum IndexKind {
Expand Down Expand Up @@ -7162,7 +7171,6 @@ export interface InferenceContext {
mapper: TypeMapper; // Mapper that fixes inferences
nonFixingMapper: TypeMapper; // Mapper that doesn't fix inferences
returnMapper?: TypeMapper; // Type mapper for inferences from return types (if any)
outerReturnMapper?: TypeMapper; // Type mapper for inferences from return types of outer function (if any)
inferredTypeParameters?: readonly TypeParameter[]; // Inferred type parameters for function result
intraExpressionInferenceSites?: IntraExpressionInferenceSite[];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6718,11 +6718,11 @@ declare namespace ts {
JSLiteral = 4096,
FreshLiteral = 8192,
ArrayLiteral = 16384,
SingleSignatureType = 134217728,
ClassOrInterface = 3,
ContainsSpread = 2097152,
ObjectRestType = 4194304,
InstantiationExpressionType = 8388608,
SingleSignatureType = 134217728,
}
interface ObjectType extends Type {
objectFlags: ObjectFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ type Result1 = ComponentProps<typeof ComponentWithForwardRef>;

// that could be incorrectly reused by this one
type Result2 = Test<{ component: typeof ComponentWithForwardRef }>; // no `T` leak
>Result2 : Omit<any, "ref"> & { ref?: Ref<HTMLElement> | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Result2 : PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>component : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>ComponentWithForwardRef : <T extends FunctionComponent<any>>(props: PropsWithoutRef<ComponentProps<T>> & { ref?: Ref<HTMLElement> | undefined; }) => unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,30 @@ export declare const outer: ProxyMap<XXX>;
> : ^^^^^^^^^^^^^

export const a = inner.log(100); // Effect<100, never, never>
>a : F<Effect<100, never, never>, this>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>inner.log(100) : F<Effect<100, never, never>, this>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>inner.log : <N extends number>(n: N) => F<Effect<N, never, never>, this>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>a : Effect<100, never, never>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>inner.log(100) : Effect<100, never, never>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>inner.log : <N extends number>(n: N) => Effect<N, never, never>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>inner : XXX
> : ^^^
>log : <N extends number>(n: N) => F<Effect<N, never, never>, this>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>log : <N extends number>(n: N) => Effect<N, never, never>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>100 : 100
> : ^^^

export const b = outer.log(100); // Effect<100, never, XXX>
>b : F<Effect<100, never, never>, this>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>outer.log(100) : F<Effect<100, never, never>, this>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>outer.log : <N extends number>(n: N) => F<Effect<N, never, never>, this>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>b : Effect<100, never, never>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>outer.log(100) : Effect<100, never, never>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>outer.log : <N extends number>(n: N) => Effect<N, never, never>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>outer : ProxyMap<XXX>
> : ^^^^^^^^^^^^^
>log : <N extends number>(n: N) => F<Effect<N, never, never>, this>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>log : <N extends number>(n: N) => Effect<N, never, never>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>100 : 100
> : ^^^

Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ const added3 = addedSome3({ c: true });
> : ^^^^

const addP3_other = withP3({ foo: 'bar' });
>addP3_other : <I>(from: I) => <I2>(from2: I2) => I & I2 & { foo: string; }
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>withP3({ foo: 'bar' }) : <I>(from: I) => <I2>(from2: I2) => I & I2 & { foo: string; }
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addP3_other : <I>(from: I) => <I2>(from2: I2) => I & I2 & { a: number; }
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>withP3({ foo: 'bar' }) : <I>(from: I) => <I2>(from2: I2) => I & I2 & { a: number; }
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>withP3 : <P>(p: P) => <I>(from: I) => <I2>(from2: I2) => I & I2 & P
> : ^ ^^ ^^ ^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^
>{ foo: 'bar' } : { foo: string; }
Expand All @@ -172,12 +172,12 @@ const addP3_other = withP3({ foo: 'bar' });
> : ^^^^^

const addedSome3_other = addP3_other({ qwerty: 123 });
>addedSome3_other : <I2>(from2: I2) => { qwerty: number; } & I2 & { foo: string; }
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addP3_other({ qwerty: 123 }) : <I2>(from2: I2) => { qwerty: number; } & I2 & { foo: string; }
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addP3_other : <I>(from: I) => <I2>(from2: I2) => I & I2 & { foo: string; }
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addedSome3_other : <I2>(from2: I2) => { qwerty: number; } & I2 & { a: number; }
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addP3_other({ qwerty: 123 }) : <I2>(from2: I2) => { qwerty: number; } & I2 & { a: number; }
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addP3_other : <I>(from: I) => <I2>(from2: I2) => I & I2 & { a: number; }
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ qwerty: 123 } : { qwerty: number; }
> : ^^^^^^^^^^^^^^^^^^^
>qwerty : number
Expand All @@ -186,12 +186,12 @@ const addedSome3_other = addP3_other({ qwerty: 123 });
> : ^^^

const added3_other = addedSome3_other({ bazinga: true });
>added3_other : { qwerty: number; } & { bazinga: boolean; } & { foo: string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addedSome3_other({ bazinga: true }) : { qwerty: number; } & { bazinga: boolean; } & { foo: string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addedSome3_other : <I2>(from2: I2) => { qwerty: number; } & I2 & { foo: string; }
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>added3_other : { qwerty: number; } & { bazinga: boolean; } & { a: number; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addedSome3_other({ bazinga: true }) : { qwerty: number; } & { bazinga: boolean; } & { a: number; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>addedSome3_other : <I2>(from2: I2) => { qwerty: number; } & I2 & { a: number; }
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ bazinga: true } : { bazinga: true; }
> : ^^^^^^^^^^^^^^^^^^
>bazinga : true
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/genericFunctionInference1.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

=== Performance Stats ===
Type Count: 1,000
Instantiation count: 1,000
Instantiation count: 2,500

=== genericFunctionInference1.ts ===
declare function pipe<A extends any[], B>(ab: (...args: A) => B): (...args: A) => B;
Expand Down
21 changes: 21 additions & 0 deletions tests/baselines/reference/inferencePromiseArrays1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/inferencePromiseArrays1.ts] ////

//// [inferencePromiseArrays1.ts]
declare function getNum(): Promise<number>;
declare function getStr(): Promise<string>;
declare function useTuple(tuple: [number, string]): void;
const p1 = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then(useTuple);

const p2 = Promise.resolve([]).then(()=> {
return Promise.all([0, ""]);
})
const p3: Promise<[number, string]> = p2;


//// [inferencePromiseArrays1.js]
"use strict";
const p1 = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then(useTuple);
const p2 = Promise.resolve([]).then(() => {
return Promise.all([0, ""]);
});
const p3 = p2;
50 changes: 50 additions & 0 deletions tests/baselines/reference/inferencePromiseArrays1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//// [tests/cases/compiler/inferencePromiseArrays1.ts] ////

=== inferencePromiseArrays1.ts ===
declare function getNum(): Promise<number>;
>getNum : Symbol(getNum, Decl(inferencePromiseArrays1.ts, 0, 0))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))

declare function getStr(): Promise<string>;
>getStr : Symbol(getStr, Decl(inferencePromiseArrays1.ts, 0, 43))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))

declare function useTuple(tuple: [number, string]): void;
>useTuple : Symbol(useTuple, Decl(inferencePromiseArrays1.ts, 1, 43))
>tuple : Symbol(tuple, Decl(inferencePromiseArrays1.ts, 2, 26))

const p1 = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then(useTuple);
>p1 : Symbol(p1, Decl(inferencePromiseArrays1.ts, 3, 5))
>Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>Promise.resolve([]).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>getNum : Symbol(getNum, Decl(inferencePromiseArrays1.ts, 0, 0))
>getStr : Symbol(getStr, Decl(inferencePromiseArrays1.ts, 0, 43))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>useTuple : Symbol(useTuple, Decl(inferencePromiseArrays1.ts, 1, 43))

const p2 = Promise.resolve([]).then(()=> {
>p2 : Symbol(p2, Decl(inferencePromiseArrays1.ts, 5, 5))
>Promise.resolve([]).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))

return Promise.all([0, ""]);
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))

})
const p3: Promise<[number, string]> = p2;
>p3 : Symbol(p3, Decl(inferencePromiseArrays1.ts, 8, 5))
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
>p2 : Symbol(p2, Decl(inferencePromiseArrays1.ts, 5, 5))

Loading
Loading