Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Sep 8, 2022
1 parent 2f1ba45 commit 3644959
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/baselines/reference/issue50680.errors.txt
Original file line number Diff line number Diff line change
@@ -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<T extends string>(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;
}

41 changes: 41 additions & 0 deletions tests/baselines/reference/issue50680.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//// [issue50680.ts]
declare function func<T extends string>(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;
}
73 changes: 73 additions & 0 deletions tests/baselines/reference/issue50680.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
=== tests/cases/compiler/issue50680.ts ===
declare function func<T extends string>(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))
}

89 changes: 89 additions & 0 deletions tests/baselines/reference/issue50680.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
=== tests/cases/compiler/issue50680.ts ===
declare function func<T extends string>(arg: { keys: T[] }): { readonly keys: T[]; readonly firstKey: T; };
>func : <T extends string>(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 : <T extends string>(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 : <T extends string>(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 : <T extends string>(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 : <T extends string>(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")[]
}

21 changes: 21 additions & 0 deletions tests/cases/compiler/issue50680.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare function func<T extends string>(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;
}

0 comments on commit 3644959

Please sign in to comment.