Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Mar 18, 2023
1 parent 30d044e commit 9eb3d5a
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/baselines/reference/typeParameterConstModifiers.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,18 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterCon
declare function inners2<const T extends readonly any[]>(args: readonly [unknown, ...T, unknown]): T;

const test2 = inners2([1,2,3,4,5]);

// Repro from #53307

type NotEmpty<T extends Record<string, any>> = keyof T extends never ? never : T;

const thing = <const O extends Record<string, any>>(o: NotEmpty<O>) => o;

const t = thing({ foo: '' }); // readonly { foo: "" }

type NotEmptyMapped<T extends Record<string, any>> = keyof T extends never ? never : { [K in keyof T]: T[K] };

const thingMapped = <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => o;

const tMapped = thingMapped({ foo: '' }); // { foo: "" }

18 changes: 18 additions & 0 deletions tests/baselines/reference/typeParameterConstModifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ const test = inners(1,2,3,4,5);
declare function inners2<const T extends readonly any[]>(args: readonly [unknown, ...T, unknown]): T;

const test2 = inners2([1,2,3,4,5]);

// Repro from #53307

type NotEmpty<T extends Record<string, any>> = keyof T extends never ? never : T;

const thing = <const O extends Record<string, any>>(o: NotEmpty<O>) => o;

const t = thing({ foo: '' }); // readonly { foo: "" }

type NotEmptyMapped<T extends Record<string, any>> = keyof T extends never ? never : { [K in keyof T]: T[K] };

const thingMapped = <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => o;

const tMapped = thingMapped({ foo: '' }); // { foo: "" }


//// [typeParameterConstModifiers.js]
Expand Down Expand Up @@ -130,3 +144,7 @@ function set(obj, path, value) { }
set(obj, ['a', 'b', 'c'], value);
var test = inners(1, 2, 3, 4, 5);
var test2 = inners2([1, 2, 3, 4, 5]);
var thing = function (o) { return o; };
var t = thing({ foo: '' }); // readonly { foo: "" }
var thingMapped = function (o) { return o; };
var tMapped = thingMapped({ foo: '' }); // { foo: "" }
47 changes: 47 additions & 0 deletions tests/baselines/reference/typeParameterConstModifiers.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,50 @@ const test2 = inners2([1,2,3,4,5]);
>test2 : Symbol(test2, Decl(typeParameterConstModifiers.ts, 83, 5))
>inners2 : Symbol(inners2, Decl(typeParameterConstModifiers.ts, 79, 31))

// Repro from #53307

type NotEmpty<T extends Record<string, any>> = keyof T extends never ? never : T;
>NotEmpty : Symbol(NotEmpty, Decl(typeParameterConstModifiers.ts, 83, 35))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 87, 14))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 87, 14))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 87, 14))

const thing = <const O extends Record<string, any>>(o: NotEmpty<O>) => o;
>thing : Symbol(thing, Decl(typeParameterConstModifiers.ts, 89, 5))
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 89, 15))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 89, 52))
>NotEmpty : Symbol(NotEmpty, Decl(typeParameterConstModifiers.ts, 83, 35))
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 89, 15))
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 89, 52))

const t = thing({ foo: '' }); // readonly { foo: "" }
>t : Symbol(t, Decl(typeParameterConstModifiers.ts, 91, 5))
>thing : Symbol(thing, Decl(typeParameterConstModifiers.ts, 89, 5))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 91, 17))

type NotEmptyMapped<T extends Record<string, any>> = keyof T extends never ? never : { [K in keyof T]: T[K] };
>NotEmptyMapped : Symbol(NotEmptyMapped, Decl(typeParameterConstModifiers.ts, 91, 29))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 93, 88))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 93, 20))
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 93, 88))

const thingMapped = <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => o;
>thingMapped : Symbol(thingMapped, Decl(typeParameterConstModifiers.ts, 95, 5))
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 95, 21))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 95, 58))
>NotEmptyMapped : Symbol(NotEmptyMapped, Decl(typeParameterConstModifiers.ts, 91, 29))
>O : Symbol(O, Decl(typeParameterConstModifiers.ts, 95, 21))
>o : Symbol(o, Decl(typeParameterConstModifiers.ts, 95, 58))

const tMapped = thingMapped({ foo: '' }); // { foo: "" }
>tMapped : Symbol(tMapped, Decl(typeParameterConstModifiers.ts, 97, 5))
>thingMapped : Symbol(thingMapped, Decl(typeParameterConstModifiers.ts, 95, 5))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 97, 29))

36 changes: 36 additions & 0 deletions tests/baselines/reference/typeParameterConstModifiers.types
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,39 @@ const test2 = inners2([1,2,3,4,5]);
>4 : 4
>5 : 5

// Repro from #53307

type NotEmpty<T extends Record<string, any>> = keyof T extends never ? never : T;
>NotEmpty : NotEmpty<T>

const thing = <const O extends Record<string, any>>(o: NotEmpty<O>) => o;
>thing : <const O extends Record<string, any>>(o: NotEmpty<O>) => NotEmpty<O>
><const O extends Record<string, any>>(o: NotEmpty<O>) => o : <const O extends Record<string, any>>(o: NotEmpty<O>) => NotEmpty<O>
>o : NotEmpty<O>
>o : NotEmpty<O>

const t = thing({ foo: '' }); // readonly { foo: "" }
>t : { readonly foo: ""; }
>thing({ foo: '' }) : { readonly foo: ""; }
>thing : <const O extends Record<string, any>>(o: NotEmpty<O>) => NotEmpty<O>
>{ foo: '' } : { foo: ""; }
>foo : ""
>'' : ""

type NotEmptyMapped<T extends Record<string, any>> = keyof T extends never ? never : { [K in keyof T]: T[K] };
>NotEmptyMapped : NotEmptyMapped<T>

const thingMapped = <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => o;
>thingMapped : <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => NotEmptyMapped<O>
><const O extends Record<string, any>>(o: NotEmptyMapped<O>) => o : <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => NotEmptyMapped<O>
>o : NotEmptyMapped<O>
>o : NotEmptyMapped<O>

const tMapped = thingMapped({ foo: '' }); // { foo: "" }
>tMapped : { foo: ""; }
>thingMapped({ foo: '' }) : { foo: ""; }
>thingMapped : <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => NotEmptyMapped<O>
>{ foo: '' } : { foo: ""; }
>foo : ""
>'' : ""

Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ const test = inners(1,2,3,4,5);
declare function inners2<const T extends readonly any[]>(args: readonly [unknown, ...T, unknown]): T;

const test2 = inners2([1,2,3,4,5]);

// Repro from #53307

type NotEmpty<T extends Record<string, any>> = keyof T extends never ? never : T;

const thing = <const O extends Record<string, any>>(o: NotEmpty<O>) => o;

const t = thing({ foo: '' }); // readonly { foo: "" }

type NotEmptyMapped<T extends Record<string, any>> = keyof T extends never ? never : { [K in keyof T]: T[K] };

const thingMapped = <const O extends Record<string, any>>(o: NotEmptyMapped<O>) => o;

const tMapped = thingMapped({ foo: '' }); // { foo: "" }

0 comments on commit 9eb3d5a

Please sign in to comment.