Skip to content

Commit 9d4096f

Browse files
committed
Add tests
1 parent 5bbadb6 commit 9d4096f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tests/cases/conformance/types/literal/literalTypeWidening.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ function f5() {
5959
let v4 = c4;
6060
}
6161

62+
declare function widening<T>(x: T): T;
63+
declare function nonWidening<T extends string | number | symbol>(x: T): T;
64+
65+
function f6(cond: boolean) {
66+
let x1 = widening('a');
67+
let x2 = widening(10);
68+
let x3 = widening(cond ? 'a' : 10);
69+
let y1 = nonWidening('a');
70+
let y2 = nonWidening(10);
71+
let y3 = nonWidening(cond ? 'a' : 10);
72+
}
73+
6274
// Repro from #10898
6375

6476
type FAILURE = "FAILURE";
@@ -94,4 +106,24 @@ type TestEvent = "onmouseover" | "onmouseout";
94106

95107
function onMouseOver(): TestEvent { return "onmouseover"; }
96108

97-
let x = onMouseOver();
109+
let x = onMouseOver();
110+
111+
// Repro from #23649
112+
113+
export function Set<K extends string>(...keys: K[]): Record<K, true | undefined> {
114+
const result = {} as Record<K, true | undefined>
115+
keys.forEach(key => result[key] = true)
116+
return result
117+
}
118+
119+
export function keys<K extends string, V>(obj: Record<K, V>): K[] {
120+
return Object.keys(obj) as K[]
121+
}
122+
123+
type Obj = { code: LangCode }
124+
125+
const langCodeSet = Set('fr', 'en', 'es', 'it', 'nl')
126+
export type LangCode = keyof typeof langCodeSet
127+
export const langCodes = keys(langCodeSet)
128+
129+
const arr: Obj[] = langCodes.map(code => ({ code }))

0 commit comments

Comments
 (0)