From 364495996f57d7d84c64c8f7cbbb1e5b7890b8fa Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 8 Sep 2022 12:31:06 -0700 Subject: [PATCH 1/3] Add test case --- .../baselines/reference/issue50680.errors.txt | 36 ++++++++ tests/baselines/reference/issue50680.js | 41 +++++++++ tests/baselines/reference/issue50680.symbols | 73 +++++++++++++++ tests/baselines/reference/issue50680.types | 89 +++++++++++++++++++ tests/cases/compiler/issue50680.ts | 21 +++++ 5 files changed, 260 insertions(+) create mode 100644 tests/baselines/reference/issue50680.errors.txt create mode 100644 tests/baselines/reference/issue50680.js create mode 100644 tests/baselines/reference/issue50680.symbols create mode 100644 tests/baselines/reference/issue50680.types create mode 100644 tests/cases/compiler/issue50680.ts diff --git a/tests/baselines/reference/issue50680.errors.txt b/tests/baselines/reference/issue50680.errors.txt new file mode 100644 index 0000000000000..241abea1b35cf --- /dev/null +++ b/tests/baselines/reference/issue50680.errors.txt @@ -0,0 +1,36 @@ +tests/cases/compiler/issue50680.ts(5,11): error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. +tests/cases/compiler/issue50680.ts(13,11): error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. +tests/cases/compiler/issue50680.ts(14,11): error TS2322: Type 'string[]' is not assignable to type '("aa" | "bb")[]'. + Type 'string' is not assignable to type '"aa" | "bb"'. + + +==== tests/cases/compiler/issue50680.ts (3 errors) ==== + declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; + + function func1() { + const { firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. + + const { keys } = func({keys: ["aa", "bb"]}) + const b: ("aa" | "bb")[] = keys; + } + + function func2() { + const { keys, firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + ~ +!!! error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. + const b: ("aa" | "bb")[] = keys; + ~ +!!! error TS2322: Type 'string[]' is not assignable to type '("aa" | "bb")[]'. +!!! error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. + } + + function func3() { + const x = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = x.firstKey; + const b: ("aa" | "bb")[] = x.keys; + } + \ No newline at end of file diff --git a/tests/baselines/reference/issue50680.js b/tests/baselines/reference/issue50680.js new file mode 100644 index 0000000000000..6b2a360d12e41 --- /dev/null +++ b/tests/baselines/reference/issue50680.js @@ -0,0 +1,41 @@ +//// [issue50680.ts] +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; + +function func1() { + const { firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + + const { keys } = func({keys: ["aa", "bb"]}) + const b: ("aa" | "bb")[] = keys; +} + +function func2() { + const { keys, firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + const b: ("aa" | "bb")[] = keys; +} + +function func3() { + const x = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = x.firstKey; + const b: ("aa" | "bb")[] = x.keys; +} + + +//// [issue50680.js] +function func1() { + var firstKey = func({ keys: ["aa", "bb"] }).firstKey; + var a = firstKey; + var keys = func({ keys: ["aa", "bb"] }).keys; + var b = keys; +} +function func2() { + var _a = func({ keys: ["aa", "bb"] }), keys = _a.keys, firstKey = _a.firstKey; + var a = firstKey; + var b = keys; +} +function func3() { + var x = func({ keys: ["aa", "bb"] }); + var a = x.firstKey; + var b = x.keys; +} diff --git a/tests/baselines/reference/issue50680.symbols b/tests/baselines/reference/issue50680.symbols new file mode 100644 index 0000000000000..305245e7cd883 --- /dev/null +++ b/tests/baselines/reference/issue50680.symbols @@ -0,0 +1,73 @@ +=== tests/cases/compiler/issue50680.ts === +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; +>func : Symbol(func, Decl(issue50680.ts, 0, 0)) +>T : Symbol(T, Decl(issue50680.ts, 0, 22)) +>arg : Symbol(arg, Decl(issue50680.ts, 0, 40)) +>keys : Symbol(keys, Decl(issue50680.ts, 0, 46)) +>T : Symbol(T, Decl(issue50680.ts, 0, 22)) +>keys : Symbol(keys, Decl(issue50680.ts, 0, 62)) +>T : Symbol(T, Decl(issue50680.ts, 0, 22)) +>firstKey : Symbol(firstKey, Decl(issue50680.ts, 0, 82)) +>T : Symbol(T, Decl(issue50680.ts, 0, 22)) + +function func1() { +>func1 : Symbol(func1, Decl(issue50680.ts, 0, 107)) + + const { firstKey } = func({keys: ["aa", "bb"]}) +>firstKey : Symbol(firstKey, Decl(issue50680.ts, 3, 11)) +>func : Symbol(func, Decl(issue50680.ts, 0, 0)) +>keys : Symbol(keys, Decl(issue50680.ts, 3, 31)) + + const a: "aa" | "bb" = firstKey; +>a : Symbol(a, Decl(issue50680.ts, 4, 9)) +>firstKey : Symbol(firstKey, Decl(issue50680.ts, 3, 11)) + + const { keys } = func({keys: ["aa", "bb"]}) +>keys : Symbol(keys, Decl(issue50680.ts, 6, 11)) +>func : Symbol(func, Decl(issue50680.ts, 0, 0)) +>keys : Symbol(keys, Decl(issue50680.ts, 6, 27)) + + const b: ("aa" | "bb")[] = keys; +>b : Symbol(b, Decl(issue50680.ts, 7, 9)) +>keys : Symbol(keys, Decl(issue50680.ts, 6, 11)) +} + +function func2() { +>func2 : Symbol(func2, Decl(issue50680.ts, 8, 1)) + + const { keys, firstKey } = func({keys: ["aa", "bb"]}) +>keys : Symbol(keys, Decl(issue50680.ts, 11, 11)) +>firstKey : Symbol(firstKey, Decl(issue50680.ts, 11, 17)) +>func : Symbol(func, Decl(issue50680.ts, 0, 0)) +>keys : Symbol(keys, Decl(issue50680.ts, 11, 37)) + + const a: "aa" | "bb" = firstKey; +>a : Symbol(a, Decl(issue50680.ts, 12, 9)) +>firstKey : Symbol(firstKey, Decl(issue50680.ts, 11, 17)) + + const b: ("aa" | "bb")[] = keys; +>b : Symbol(b, Decl(issue50680.ts, 13, 9)) +>keys : Symbol(keys, Decl(issue50680.ts, 11, 11)) +} + +function func3() { +>func3 : Symbol(func3, Decl(issue50680.ts, 14, 1)) + + const x = func({keys: ["aa", "bb"]}) +>x : Symbol(x, Decl(issue50680.ts, 17, 9)) +>func : Symbol(func, Decl(issue50680.ts, 0, 0)) +>keys : Symbol(keys, Decl(issue50680.ts, 17, 20)) + + const a: "aa" | "bb" = x.firstKey; +>a : Symbol(a, Decl(issue50680.ts, 18, 9)) +>x.firstKey : Symbol(firstKey, Decl(issue50680.ts, 0, 82)) +>x : Symbol(x, Decl(issue50680.ts, 17, 9)) +>firstKey : Symbol(firstKey, Decl(issue50680.ts, 0, 82)) + + const b: ("aa" | "bb")[] = x.keys; +>b : Symbol(b, Decl(issue50680.ts, 19, 9)) +>x.keys : Symbol(keys, Decl(issue50680.ts, 0, 62)) +>x : Symbol(x, Decl(issue50680.ts, 17, 9)) +>keys : Symbol(keys, Decl(issue50680.ts, 0, 62)) +} + diff --git a/tests/baselines/reference/issue50680.types b/tests/baselines/reference/issue50680.types new file mode 100644 index 0000000000000..1ad1f004f58f5 --- /dev/null +++ b/tests/baselines/reference/issue50680.types @@ -0,0 +1,89 @@ +=== tests/cases/compiler/issue50680.ts === +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; +>func : (arg: { keys: T[];}) => { readonly keys: T[]; readonly firstKey: T;} +>arg : { keys: T[]; } +>keys : T[] +>keys : T[] +>firstKey : T + +function func1() { +>func1 : () => void + + const { firstKey } = func({keys: ["aa", "bb"]}) +>firstKey : string +>func({keys: ["aa", "bb"]}) : { readonly keys: string[]; readonly firstKey: string; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: string[]; } +>keys : string[] +>["aa", "bb"] : string[] +>"aa" : "aa" +>"bb" : "bb" + + const a: "aa" | "bb" = firstKey; +>a : "aa" | "bb" +>firstKey : string + + const { keys } = func({keys: ["aa", "bb"]}) +>keys : ("aa" | "bb")[] +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] +>"aa" : "aa" +>"bb" : "bb" + + const b: ("aa" | "bb")[] = keys; +>b : ("aa" | "bb")[] +>keys : ("aa" | "bb")[] +} + +function func2() { +>func2 : () => void + + const { keys, firstKey } = func({keys: ["aa", "bb"]}) +>keys : string[] +>firstKey : string +>func({keys: ["aa", "bb"]}) : { readonly keys: string[]; readonly firstKey: string; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: string[]; } +>keys : string[] +>["aa", "bb"] : string[] +>"aa" : "aa" +>"bb" : "bb" + + const a: "aa" | "bb" = firstKey; +>a : "aa" | "bb" +>firstKey : string + + const b: ("aa" | "bb")[] = keys; +>b : ("aa" | "bb")[] +>keys : string[] +} + +function func3() { +>func3 : () => void + + const x = func({keys: ["aa", "bb"]}) +>x : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] +>"aa" : "aa" +>"bb" : "bb" + + const a: "aa" | "bb" = x.firstKey; +>a : "aa" | "bb" +>x.firstKey : "aa" | "bb" +>x : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>firstKey : "aa" | "bb" + + const b: ("aa" | "bb")[] = x.keys; +>b : ("aa" | "bb")[] +>x.keys : ("aa" | "bb")[] +>x : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } +>keys : ("aa" | "bb")[] +} + diff --git a/tests/cases/compiler/issue50680.ts b/tests/cases/compiler/issue50680.ts new file mode 100644 index 0000000000000..0b8727ea5a0ce --- /dev/null +++ b/tests/cases/compiler/issue50680.ts @@ -0,0 +1,21 @@ +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; + +function func1() { + const { firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + + const { keys } = func({keys: ["aa", "bb"]}) + const b: ("aa" | "bb")[] = keys; +} + +function func2() { + const { keys, firstKey } = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = firstKey; + const b: ("aa" | "bb")[] = keys; +} + +function func3() { + const x = func({keys: ["aa", "bb"]}) + const a: "aa" | "bb" = x.firstKey; + const b: ("aa" | "bb")[] = x.keys; +} From 17f6e5723f50b1f642a707dff2a718f187145b1b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 8 Sep 2022 13:23:26 -0700 Subject: [PATCH 2/3] Revert removal of nonInferrableAnyType --- src/compiler/checker.ts | 12 +++++-- .../baselines/reference/issue50680.errors.txt | 36 ------------------- tests/baselines/reference/issue50680.types | 28 +++++++-------- 3 files changed, 24 insertions(+), 52 deletions(-) delete mode 100644 tests/baselines/reference/issue50680.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6da3c9e760c3f..43bd84675cc3e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -791,6 +791,7 @@ namespace ts { const wildcardType = createIntrinsicType(TypeFlags.Any, "any"); const errorType = createIntrinsicType(TypeFlags.Any, "error"); const unresolvedType = createIntrinsicType(TypeFlags.Any, "unresolved"); + const nonInferrableAnyType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.ContainsWideningType); const intrinsicMarkerType = createIntrinsicType(TypeFlags.Any, "intrinsic"); const unknownType = createIntrinsicType(TypeFlags.Unknown, "unknown"); const nonNullUnknownType = createIntrinsicType(TypeFlags.Unknown, "unknown"); @@ -9560,7 +9561,11 @@ namespace ts { if (reportErrors && !declarationBelongsToPrivateAmbientMember(element)) { reportImplicitAny(element, anyType); } - return anyType; + // When we're including the pattern in the type (an indication we're obtaining a contextual type), we + // use a non-inferrable any type. Inference will never directly infer this type, but it is possible + // to infer a type that contains it, e.g. for a binding pattern like [foo] or { foo }. In such cases, + // widening of the binding pattern type substitutes a regular any for the non-inferrable any. + return includePatternInType ? nonInferrableAnyType : anyType; } // Return the type implied by an object binding pattern @@ -22631,7 +22636,10 @@ namespace ts { // // This flag is infectious; if we produce Box (where never is silentNeverType), Box is // also non-inferrable. - if (getObjectFlags(source) & ObjectFlags.NonInferrableType) { + // + // As a special case, also ignore nonInferrableAnyType, which is a special form of the any type + // used as a stand-in for binding elements when they are being inferred. + if (getObjectFlags(source) & ObjectFlags.NonInferrableType || source === nonInferrableAnyType) { return; } if (!inference.isFixed) { diff --git a/tests/baselines/reference/issue50680.errors.txt b/tests/baselines/reference/issue50680.errors.txt deleted file mode 100644 index 241abea1b35cf..0000000000000 --- a/tests/baselines/reference/issue50680.errors.txt +++ /dev/null @@ -1,36 +0,0 @@ -tests/cases/compiler/issue50680.ts(5,11): error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. -tests/cases/compiler/issue50680.ts(13,11): error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. -tests/cases/compiler/issue50680.ts(14,11): error TS2322: Type 'string[]' is not assignable to type '("aa" | "bb")[]'. - Type 'string' is not assignable to type '"aa" | "bb"'. - - -==== tests/cases/compiler/issue50680.ts (3 errors) ==== - declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; - - function func1() { - const { firstKey } = func({keys: ["aa", "bb"]}) - const a: "aa" | "bb" = firstKey; - ~ -!!! error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. - - const { keys } = func({keys: ["aa", "bb"]}) - const b: ("aa" | "bb")[] = keys; - } - - function func2() { - const { keys, firstKey } = func({keys: ["aa", "bb"]}) - const a: "aa" | "bb" = firstKey; - ~ -!!! error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. - const b: ("aa" | "bb")[] = keys; - ~ -!!! error TS2322: Type 'string[]' is not assignable to type '("aa" | "bb")[]'. -!!! error TS2322: Type 'string' is not assignable to type '"aa" | "bb"'. - } - - function func3() { - const x = func({keys: ["aa", "bb"]}) - const a: "aa" | "bb" = x.firstKey; - const b: ("aa" | "bb")[] = x.keys; - } - \ No newline at end of file diff --git a/tests/baselines/reference/issue50680.types b/tests/baselines/reference/issue50680.types index 1ad1f004f58f5..860ee69a1d070 100644 --- a/tests/baselines/reference/issue50680.types +++ b/tests/baselines/reference/issue50680.types @@ -10,18 +10,18 @@ function func1() { >func1 : () => void const { firstKey } = func({keys: ["aa", "bb"]}) ->firstKey : string ->func({keys: ["aa", "bb"]}) : { readonly keys: string[]; readonly firstKey: string; } +>firstKey : "aa" | "bb" +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } >func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } ->{keys: ["aa", "bb"]} : { keys: string[]; } ->keys : string[] ->["aa", "bb"] : string[] +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] >"aa" : "aa" >"bb" : "bb" const a: "aa" | "bb" = firstKey; >a : "aa" | "bb" ->firstKey : string +>firstKey : "aa" | "bb" const { keys } = func({keys: ["aa", "bb"]}) >keys : ("aa" | "bb")[] @@ -42,23 +42,23 @@ function func2() { >func2 : () => void const { keys, firstKey } = func({keys: ["aa", "bb"]}) ->keys : string[] ->firstKey : string ->func({keys: ["aa", "bb"]}) : { readonly keys: string[]; readonly firstKey: string; } +>keys : ("aa" | "bb")[] +>firstKey : "aa" | "bb" +>func({keys: ["aa", "bb"]}) : { readonly keys: ("aa" | "bb")[]; readonly firstKey: "aa" | "bb"; } >func : (arg: { keys: T[]; }) => { readonly keys: T[]; readonly firstKey: T; } ->{keys: ["aa", "bb"]} : { keys: string[]; } ->keys : string[] ->["aa", "bb"] : string[] +>{keys: ["aa", "bb"]} : { keys: ("aa" | "bb")[]; } +>keys : ("aa" | "bb")[] +>["aa", "bb"] : ("aa" | "bb")[] >"aa" : "aa" >"bb" : "bb" const a: "aa" | "bb" = firstKey; >a : "aa" | "bb" ->firstKey : string +>firstKey : "aa" | "bb" const b: ("aa" | "bb")[] = keys; >b : ("aa" | "bb")[] ->keys : string[] +>keys : ("aa" | "bb")[] } function func3() { From cafebeeeb57233862cbe9cef7dd63d84d128db2b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 8 Sep 2022 13:25:18 -0700 Subject: [PATCH 3/3] Rename test --- ...ferStringLiteralUnionForBindingElement.js} | 4 +- ...tringLiteralUnionForBindingElement.symbols | 73 +++++++++++++++++++ ...StringLiteralUnionForBindingElement.types} | 2 +- tests/baselines/reference/issue50680.symbols | 73 ------------------- ...ferStringLiteralUnionForBindingElement.ts} | 0 5 files changed, 76 insertions(+), 76 deletions(-) rename tests/baselines/reference/{issue50680.js => inferStringLiteralUnionForBindingElement.js} (89%) create mode 100644 tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols rename tests/baselines/reference/{issue50680.types => inferStringLiteralUnionForBindingElement.types} (94%) delete mode 100644 tests/baselines/reference/issue50680.symbols rename tests/cases/compiler/{issue50680.ts => inferStringLiteralUnionForBindingElement.ts} (100%) diff --git a/tests/baselines/reference/issue50680.js b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.js similarity index 89% rename from tests/baselines/reference/issue50680.js rename to tests/baselines/reference/inferStringLiteralUnionForBindingElement.js index 6b2a360d12e41..e5c5527287a16 100644 --- a/tests/baselines/reference/issue50680.js +++ b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.js @@ -1,4 +1,4 @@ -//// [issue50680.ts] +//// [inferStringLiteralUnionForBindingElement.ts] declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; function func1() { @@ -22,7 +22,7 @@ function func3() { } -//// [issue50680.js] +//// [inferStringLiteralUnionForBindingElement.js] function func1() { var firstKey = func({ keys: ["aa", "bb"] }).firstKey; var a = firstKey; diff --git a/tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols new file mode 100644 index 0000000000000..1b19c0132ce79 --- /dev/null +++ b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.symbols @@ -0,0 +1,73 @@ +=== tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts === +declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) +>arg : Symbol(arg, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 40)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 46)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 62)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 82)) +>T : Symbol(T, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 22)) + +function func1() { +>func1 : Symbol(func1, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 107)) + + const { firstKey } = func({keys: ["aa", "bb"]}) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 3, 11)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 3, 31)) + + const a: "aa" | "bb" = firstKey; +>a : Symbol(a, Decl(inferStringLiteralUnionForBindingElement.ts, 4, 9)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 3, 11)) + + const { keys } = func({keys: ["aa", "bb"]}) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 6, 11)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 6, 27)) + + const b: ("aa" | "bb")[] = keys; +>b : Symbol(b, Decl(inferStringLiteralUnionForBindingElement.ts, 7, 9)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 6, 11)) +} + +function func2() { +>func2 : Symbol(func2, Decl(inferStringLiteralUnionForBindingElement.ts, 8, 1)) + + const { keys, firstKey } = func({keys: ["aa", "bb"]}) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 11)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 17)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 37)) + + const a: "aa" | "bb" = firstKey; +>a : Symbol(a, Decl(inferStringLiteralUnionForBindingElement.ts, 12, 9)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 17)) + + const b: ("aa" | "bb")[] = keys; +>b : Symbol(b, Decl(inferStringLiteralUnionForBindingElement.ts, 13, 9)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 11, 11)) +} + +function func3() { +>func3 : Symbol(func3, Decl(inferStringLiteralUnionForBindingElement.ts, 14, 1)) + + const x = func({keys: ["aa", "bb"]}) +>x : Symbol(x, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 9)) +>func : Symbol(func, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 0)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 20)) + + const a: "aa" | "bb" = x.firstKey; +>a : Symbol(a, Decl(inferStringLiteralUnionForBindingElement.ts, 18, 9)) +>x.firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 82)) +>x : Symbol(x, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 9)) +>firstKey : Symbol(firstKey, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 82)) + + const b: ("aa" | "bb")[] = x.keys; +>b : Symbol(b, Decl(inferStringLiteralUnionForBindingElement.ts, 19, 9)) +>x.keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 62)) +>x : Symbol(x, Decl(inferStringLiteralUnionForBindingElement.ts, 17, 9)) +>keys : Symbol(keys, Decl(inferStringLiteralUnionForBindingElement.ts, 0, 62)) +} + diff --git a/tests/baselines/reference/issue50680.types b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.types similarity index 94% rename from tests/baselines/reference/issue50680.types rename to tests/baselines/reference/inferStringLiteralUnionForBindingElement.types index 860ee69a1d070..0d3cf898877f1 100644 --- a/tests/baselines/reference/issue50680.types +++ b/tests/baselines/reference/inferStringLiteralUnionForBindingElement.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/issue50680.ts === +=== tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts === declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; >func : (arg: { keys: T[];}) => { readonly keys: T[]; readonly firstKey: T;} >arg : { keys: T[]; } diff --git a/tests/baselines/reference/issue50680.symbols b/tests/baselines/reference/issue50680.symbols deleted file mode 100644 index 305245e7cd883..0000000000000 --- a/tests/baselines/reference/issue50680.symbols +++ /dev/null @@ -1,73 +0,0 @@ -=== tests/cases/compiler/issue50680.ts === -declare function func(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; }; ->func : Symbol(func, Decl(issue50680.ts, 0, 0)) ->T : Symbol(T, Decl(issue50680.ts, 0, 22)) ->arg : Symbol(arg, Decl(issue50680.ts, 0, 40)) ->keys : Symbol(keys, Decl(issue50680.ts, 0, 46)) ->T : Symbol(T, Decl(issue50680.ts, 0, 22)) ->keys : Symbol(keys, Decl(issue50680.ts, 0, 62)) ->T : Symbol(T, Decl(issue50680.ts, 0, 22)) ->firstKey : Symbol(firstKey, Decl(issue50680.ts, 0, 82)) ->T : Symbol(T, Decl(issue50680.ts, 0, 22)) - -function func1() { ->func1 : Symbol(func1, Decl(issue50680.ts, 0, 107)) - - const { firstKey } = func({keys: ["aa", "bb"]}) ->firstKey : Symbol(firstKey, Decl(issue50680.ts, 3, 11)) ->func : Symbol(func, Decl(issue50680.ts, 0, 0)) ->keys : Symbol(keys, Decl(issue50680.ts, 3, 31)) - - const a: "aa" | "bb" = firstKey; ->a : Symbol(a, Decl(issue50680.ts, 4, 9)) ->firstKey : Symbol(firstKey, Decl(issue50680.ts, 3, 11)) - - const { keys } = func({keys: ["aa", "bb"]}) ->keys : Symbol(keys, Decl(issue50680.ts, 6, 11)) ->func : Symbol(func, Decl(issue50680.ts, 0, 0)) ->keys : Symbol(keys, Decl(issue50680.ts, 6, 27)) - - const b: ("aa" | "bb")[] = keys; ->b : Symbol(b, Decl(issue50680.ts, 7, 9)) ->keys : Symbol(keys, Decl(issue50680.ts, 6, 11)) -} - -function func2() { ->func2 : Symbol(func2, Decl(issue50680.ts, 8, 1)) - - const { keys, firstKey } = func({keys: ["aa", "bb"]}) ->keys : Symbol(keys, Decl(issue50680.ts, 11, 11)) ->firstKey : Symbol(firstKey, Decl(issue50680.ts, 11, 17)) ->func : Symbol(func, Decl(issue50680.ts, 0, 0)) ->keys : Symbol(keys, Decl(issue50680.ts, 11, 37)) - - const a: "aa" | "bb" = firstKey; ->a : Symbol(a, Decl(issue50680.ts, 12, 9)) ->firstKey : Symbol(firstKey, Decl(issue50680.ts, 11, 17)) - - const b: ("aa" | "bb")[] = keys; ->b : Symbol(b, Decl(issue50680.ts, 13, 9)) ->keys : Symbol(keys, Decl(issue50680.ts, 11, 11)) -} - -function func3() { ->func3 : Symbol(func3, Decl(issue50680.ts, 14, 1)) - - const x = func({keys: ["aa", "bb"]}) ->x : Symbol(x, Decl(issue50680.ts, 17, 9)) ->func : Symbol(func, Decl(issue50680.ts, 0, 0)) ->keys : Symbol(keys, Decl(issue50680.ts, 17, 20)) - - const a: "aa" | "bb" = x.firstKey; ->a : Symbol(a, Decl(issue50680.ts, 18, 9)) ->x.firstKey : Symbol(firstKey, Decl(issue50680.ts, 0, 82)) ->x : Symbol(x, Decl(issue50680.ts, 17, 9)) ->firstKey : Symbol(firstKey, Decl(issue50680.ts, 0, 82)) - - const b: ("aa" | "bb")[] = x.keys; ->b : Symbol(b, Decl(issue50680.ts, 19, 9)) ->x.keys : Symbol(keys, Decl(issue50680.ts, 0, 62)) ->x : Symbol(x, Decl(issue50680.ts, 17, 9)) ->keys : Symbol(keys, Decl(issue50680.ts, 0, 62)) -} - diff --git a/tests/cases/compiler/issue50680.ts b/tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts similarity index 100% rename from tests/cases/compiler/issue50680.ts rename to tests/cases/compiler/inferStringLiteralUnionForBindingElement.ts