@@ -60,6 +60,18 @@ function f5() {
6060 let v4 = c4 ;
6161}
6262
63+ declare function widening < T > ( x : T ) : T ;
64+ declare function nonWidening < T extends string | number | symbol > ( x : T ) : T ;
65+
66+ function f6 ( cond : boolean ) {
67+ let x1 = widening ( 'a' ) ;
68+ let x2 = widening ( 10 ) ;
69+ let x3 = widening ( cond ? 'a' : 10 ) ;
70+ let y1 = nonWidening ( 'a' ) ;
71+ let y2 = nonWidening ( 10 ) ;
72+ let y3 = nonWidening ( cond ? 'a' : 10 ) ;
73+ }
74+
6375// Repro from #10898
6476
6577type FAILURE = "FAILURE" ;
@@ -95,10 +107,33 @@ type TestEvent = "onmouseover" | "onmouseout";
95107
96108function onMouseOver(): TestEvent { return "onmouseover" ; }
97109
98- let x = onMouseOver();
110+ let x = onMouseOver();
111+
112+ // Repro from #23649
113+
114+ export function Set< K extends string > (...keys: K[]): Record< K , true | undefined > {
115+ const result = { } as Record < K , true | undefined >
116+ keys . forEach ( key => result [ key ] = true )
117+ return result
118+ }
119+
120+ export function keys< K extends string , V > (obj: Record< K , V > ): K[] {
121+ return Object . keys ( obj ) as K [ ]
122+ }
123+
124+ type Obj = { code : LangCode }
125+
126+ const langCodeSet = Set('fr', 'en', 'es', 'it', 'nl')
127+ export type LangCode = keyof typeof langCodeSet
128+ export const langCodes = keys(langCodeSet)
129+
130+ const arr: Obj[] = langCodes.map(code => ( { code } ))
131+
99132
100133//// [literalTypeWidening.js]
134+ "use strict";
101135// Widening vs. non-widening literal types
136+ exports.__esModule = true;
102137function f1() {
103138 var c1 = "hello" ; // Widening type "hello"
104139 var v1 = c1 ; // Type string
@@ -153,6 +188,14 @@ function f5() {
153188 var c4 = "foo" ;
154189 var v4 = c4 ;
155190}
191+ function f6(cond) {
192+ var x1 = widening ( 'a' ) ;
193+ var x2 = widening ( 10 ) ;
194+ var x3 = widening ( cond ? 'a' : 10 ) ;
195+ var y1 = nonWidening ( 'a' ) ;
196+ var y2 = nonWidening ( 10 ) ;
197+ var y3 = nonWidening ( cond ? 'a' : 10 ) ;
198+ }
156199var FAILURE = "FAILURE";
157200function doWork() {
158201 return FAILURE ;
@@ -172,3 +215,21 @@ if (isSuccess(result)) {
172215}
173216function onMouseOver() { return "onmouseover" ; }
174217var x = onMouseOver();
218+ // Repro from #23649
219+ function Set() {
220+ var keys = [ ] ;
221+ for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
222+ keys [ _i ] = arguments [ _i ] ;
223+ }
224+ var result = { } ;
225+ keys.forEach(function (key) { return result [ key ] = true ; } );
226+ return result;
227+ }
228+ exports . Set = Set ;
229+ function keys ( obj ) {
230+ return Object . keys ( obj ) ;
231+ }
232+ exports.keys = keys;
233+ var langCodeSet = Set('fr', 'en', 'es', 'it', 'nl');
234+ exports.langCodes = keys(langCodeSet);
235+ var arr = exports.langCodes.map(function (code) { return ( { code : code } ) ; } );
0 commit comments