diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 223abcefeebbb..d20a8710d5dcd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18995,7 +18995,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function instantiateAnonymousType(type: AnonymousType, mapper: TypeMapper, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): AnonymousType { - const result = createObjectType(type.objectFlags & ~(ObjectFlags.CouldContainTypeVariablesComputed | ObjectFlags.CouldContainTypeVariables) | ObjectFlags.Instantiated, type.symbol) as AnonymousType; + const result = createObjectType(type.objectFlags | ObjectFlags.Instantiated, type.symbol) as AnonymousType; if (type.objectFlags & ObjectFlags.Mapped) { (result as MappedType).declaration = (type as MappedType).declaration; // C.f. instantiateSignature diff --git a/tests/baselines/reference/carryingForwardTypeVariableContainment.js b/tests/baselines/reference/carryingForwardTypeVariableContainment.js new file mode 100644 index 0000000000000..abe195486bc46 --- /dev/null +++ b/tests/baselines/reference/carryingForwardTypeVariableContainment.js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/types/typeParameters/typeParameterLists/carryingForwardTypeVariableContainment.ts] //// + +//// [a.ts] +export type Brand = + Base & { [K in ReservedName]: Branding } & { __witness__: Base }; +export type BoundedInteger = + Brand; +export const toBoundedInteger = + (bounds: { lowerBound: LowerBound; upperBound: UpperBound; }) => + (n: number): BoundedInteger => ({} as any); + +//// [b.ts] +export type LexicalCommand = Record; +export type InsertTextPayload = Readonly<{ text: string }>; +function createCommand(): LexicalCommand { + return { }; +} +export const INSERT_TEXT_COMMAND = createCommand(); + + + + +//// [a.d.ts] +export type Brand = Base & { + [K in ReservedName]: Branding; +} & { + __witness__: Base; +}; +export type BoundedInteger = Brand; +export declare const toBoundedInteger: (bounds: { + lowerBound: LowerBound; + upperBound: UpperBound; +}) => (n: number) => BoundedInteger; +//// [b.d.ts] +export type LexicalCommand = Record; +export type InsertTextPayload = Readonly<{ + text: string; +}>; +export declare const INSERT_TEXT_COMMAND: LexicalCommand; diff --git a/tests/baselines/reference/carryingForwardTypeVariableContainment.symbols b/tests/baselines/reference/carryingForwardTypeVariableContainment.symbols new file mode 100644 index 0000000000000..fb553efec2306 --- /dev/null +++ b/tests/baselines/reference/carryingForwardTypeVariableContainment.symbols @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/types/typeParameters/typeParameterLists/carryingForwardTypeVariableContainment.ts] //// + +=== /a.ts === +export type Brand = +>Brand : Symbol(Brand, Decl(a.ts, 0, 0)) +>Base : Symbol(Base, Decl(a.ts, 0, 18)) +>Branding : Symbol(Branding, Decl(a.ts, 0, 23)) +>ReservedName : Symbol(ReservedName, Decl(a.ts, 0, 33)) + + Base & { [K in ReservedName]: Branding } & { __witness__: Base }; +>Base : Symbol(Base, Decl(a.ts, 0, 18)) +>K : Symbol(K, Decl(a.ts, 1, 14)) +>ReservedName : Symbol(ReservedName, Decl(a.ts, 0, 33)) +>Branding : Symbol(Branding, Decl(a.ts, 0, 23)) +>__witness__ : Symbol(__witness__, Decl(a.ts, 1, 48)) +>Base : Symbol(Base, Decl(a.ts, 0, 18)) + +export type BoundedInteger = +>BoundedInteger : Symbol(BoundedInteger, Decl(a.ts, 1, 69)) +>LowerBound : Symbol(LowerBound, Decl(a.ts, 2, 27)) +>UpperBound : Symbol(UpperBound, Decl(a.ts, 2, 53)) + + Brand; +>Brand : Symbol(Brand, Decl(a.ts, 0, 0)) + +export const toBoundedInteger = +>toBoundedInteger : Symbol(toBoundedInteger, Decl(a.ts, 4, 12)) + + (bounds: { lowerBound: LowerBound; upperBound: UpperBound; }) => +>LowerBound : Symbol(LowerBound, Decl(a.ts, 5, 5)) +>UpperBound : Symbol(UpperBound, Decl(a.ts, 5, 31)) +>bounds : Symbol(bounds, Decl(a.ts, 5, 59)) +>lowerBound : Symbol(lowerBound, Decl(a.ts, 5, 68)) +>LowerBound : Symbol(LowerBound, Decl(a.ts, 5, 5)) +>upperBound : Symbol(upperBound, Decl(a.ts, 5, 92)) +>UpperBound : Symbol(UpperBound, Decl(a.ts, 5, 31)) + + (n: number): BoundedInteger => ({} as any); +>n : Symbol(n, Decl(a.ts, 6, 9)) +>BoundedInteger : Symbol(BoundedInteger, Decl(a.ts, 1, 69)) +>LowerBound : Symbol(LowerBound, Decl(a.ts, 5, 5)) +>UpperBound : Symbol(UpperBound, Decl(a.ts, 5, 31)) + +=== /b.ts === +export type LexicalCommand = Record; +>LexicalCommand : Symbol(LexicalCommand, Decl(b.ts, 0, 0)) +>TPayload : Symbol(TPayload, Decl(b.ts, 0, 27)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + +export type InsertTextPayload = Readonly<{ text: string }>; +>InsertTextPayload : Symbol(InsertTextPayload, Decl(b.ts, 0, 61)) +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>text : Symbol(text, Decl(b.ts, 1, 42)) + +function createCommand(): LexicalCommand { +>createCommand : Symbol(createCommand, Decl(b.ts, 1, 59)) +>T : Symbol(T, Decl(b.ts, 2, 23)) +>LexicalCommand : Symbol(LexicalCommand, Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(b.ts, 2, 23)) + + return { }; +} +export const INSERT_TEXT_COMMAND = createCommand(); +>INSERT_TEXT_COMMAND : Symbol(INSERT_TEXT_COMMAND, Decl(b.ts, 5, 12)) +>createCommand : Symbol(createCommand, Decl(b.ts, 1, 59)) + diff --git a/tests/baselines/reference/carryingForwardTypeVariableContainment.types b/tests/baselines/reference/carryingForwardTypeVariableContainment.types new file mode 100644 index 0000000000000..2cee76ec4a067 --- /dev/null +++ b/tests/baselines/reference/carryingForwardTypeVariableContainment.types @@ -0,0 +1,48 @@ +//// [tests/cases/conformance/types/typeParameters/typeParameterLists/carryingForwardTypeVariableContainment.ts] //// + +=== /a.ts === +export type Brand = +>Brand : Brand + + Base & { [K in ReservedName]: Branding } & { __witness__: Base }; +>__witness__ : Base + +export type BoundedInteger = +>BoundedInteger : BoundedInteger + + Brand; +export const toBoundedInteger = +>toBoundedInteger : (bounds: { lowerBound: LowerBound; upperBound: UpperBound; }) => (n: number) => BoundedInteger + + (bounds: { lowerBound: LowerBound; upperBound: UpperBound; }) => +>(bounds: { lowerBound: LowerBound; upperBound: UpperBound; }) => (n: number): BoundedInteger => ({} as any) : (bounds: { lowerBound: LowerBound; upperBound: UpperBound; }) => (n: number) => BoundedInteger +>bounds : { lowerBound: LowerBound; upperBound: UpperBound; } +>lowerBound : LowerBound +>upperBound : UpperBound + + (n: number): BoundedInteger => ({} as any); +>(n: number): BoundedInteger => ({} as any) : (n: number) => BoundedInteger +>n : number +>({} as any) : any +>{} as any : any +>{} : {} + +=== /b.ts === +export type LexicalCommand = Record; +>LexicalCommand : LexicalCommand + +export type InsertTextPayload = Readonly<{ text: string }>; +>InsertTextPayload : Readonly<{ text: string; }> +>text : string + +function createCommand(): LexicalCommand { +>createCommand : () => LexicalCommand + + return { }; +>{ } : {} +} +export const INSERT_TEXT_COMMAND = createCommand(); +>INSERT_TEXT_COMMAND : LexicalCommand +>createCommand() : LexicalCommand +>createCommand : () => LexicalCommand + diff --git a/tests/cases/conformance/types/typeParameters/typeParameterLists/carryingForwardTypeVariableContainment.ts b/tests/cases/conformance/types/typeParameters/typeParameterLists/carryingForwardTypeVariableContainment.ts new file mode 100644 index 0000000000000..5e8110cdd8c31 --- /dev/null +++ b/tests/cases/conformance/types/typeParameters/typeParameterLists/carryingForwardTypeVariableContainment.ts @@ -0,0 +1,19 @@ +// @declaration: true +// @emitDeclarationOnly: true + +// @filename: /a.ts +export type Brand = + Base & { [K in ReservedName]: Branding } & { __witness__: Base }; +export type BoundedInteger = + Brand; +export const toBoundedInteger = + (bounds: { lowerBound: LowerBound; upperBound: UpperBound; }) => + (n: number): BoundedInteger => ({} as any); + +// @filename: /b.ts +export type LexicalCommand = Record; +export type InsertTextPayload = Readonly<{ text: string }>; +function createCommand(): LexicalCommand { + return { }; +} +export const INSERT_TEXT_COMMAND = createCommand();