Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Aug 1, 2023
1 parent 8f07af9 commit f6833cd
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 3 deletions.
51 changes: 50 additions & 1 deletion tests/baselines/reference/typeParameterConstModifiers.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,53 @@ typeParameterConstModifiers.ts(55,9): error TS1277: 'const' modifier can only ap
const t2_55033 = factory_55033((a: { test: number }, b: string) => {})(
{ test: 123 } as const,
"some string"
);
);

// Same with non-readonly constraint

function factory_55033_2<const T extends unknown[]>(cb: (...args: T) => void) {
return function call<const K extends T>(...args: K): K {
return {} as K;
};
}

const t1_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
{ test: 123 },
"some string"
);

const t2_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
{ test: 123 } as const,
"some string"
);

// Repro from https://github.com/microsoft/TypeScript/issues/51931

declare function fn<const T extends any[]>(...args: T): T;

const a = fn("a", false);

// More examples of non-readonly constraints

declare function fa1<const T extends unknown[]>(args: T): T;
declare function fa2<const T extends readonly unknown[]>(args: T): T;

fa1(["hello", 42]);
fa2(["hello", 42]);

declare function fb1<const T extends unknown[]>(...args: T): T;
declare function fb2<const T extends readonly unknown[]>(...args: T): T;

fb1("hello", 42);
fb2("hello", 42);

declare function fc1<const T extends unknown[]>(f: (...args: T) => void, ...args: T): T;
declare function fc2<const T extends readonly unknown[]>(f: (...args: T) => void, ...args: T): T;

fc1((a: string, b: number) => {}, "hello", 42);
fc2((a: string, b: number) => {}, "hello", 42);

declare function fn1<const T extends { foo: unknown[] }[]>(...args: T): T;

fn1({ foo: ["hello", 123] }, { foo: [true]});

71 changes: 70 additions & 1 deletion tests/baselines/reference/typeParameterConstModifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,56 @@ const t1_55033 = factory_55033((a: { test: number }, b: string) => {})(
const t2_55033 = factory_55033((a: { test: number }, b: string) => {})(
{ test: 123 } as const,
"some string"
);
);

// Same with non-readonly constraint

function factory_55033_2<const T extends unknown[]>(cb: (...args: T) => void) {
return function call<const K extends T>(...args: K): K {
return {} as K;
};
}

const t1_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
{ test: 123 },
"some string"
);

const t2_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
{ test: 123 } as const,
"some string"
);

// Repro from https://github.com/microsoft/TypeScript/issues/51931

declare function fn<const T extends any[]>(...args: T): T;

const a = fn("a", false);

// More examples of non-readonly constraints

declare function fa1<const T extends unknown[]>(args: T): T;
declare function fa2<const T extends readonly unknown[]>(args: T): T;

fa1(["hello", 42]);
fa2(["hello", 42]);

declare function fb1<const T extends unknown[]>(...args: T): T;
declare function fb2<const T extends readonly unknown[]>(...args: T): T;

fb1("hello", 42);
fb2("hello", 42);

declare function fc1<const T extends unknown[]>(f: (...args: T) => void, ...args: T): T;
declare function fc2<const T extends readonly unknown[]>(f: (...args: T) => void, ...args: T): T;

fc1((a: string, b: number) => {}, "hello", 42);
fc2((a: string, b: number) => {}, "hello", 42);

declare function fn1<const T extends { foo: unknown[] }[]>(...args: T): T;

fn1({ foo: ["hello", 123] }, { foo: [true]});


//// [typeParameterConstModifiers.js]
"use strict";
Expand Down Expand Up @@ -193,3 +242,23 @@ function factory_55033(cb) {
}
var t1_55033 = factory_55033(function (a, b) { })({ test: 123 }, "some string");
var t2_55033 = factory_55033(function (a, b) { })({ test: 123 }, "some string");
// Same with non-readonly constraint
function factory_55033_2(cb) {
return function call() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return {};
};
}
var t1_55033_2 = factory_55033_2(function (a, b) { })({ test: 123 }, "some string");
var t2_55033_2 = factory_55033_2(function (a, b) { })({ test: 123 }, "some string");
var a = fn("a", false);
fa1(["hello", 42]);
fa2(["hello", 42]);
fb1("hello", 42);
fb2("hello", 42);
fc1(function (a, b) { }, "hello", 42);
fc2(function (a, b) { }, "hello", 42);
fn1({ foo: ["hello", 123] }, { foo: [true] });
149 changes: 149 additions & 0 deletions tests/baselines/reference/typeParameterConstModifiers.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,152 @@ const t2_55033 = factory_55033((a: { test: number }, b: string) => {})(

"some string"
);

// Same with non-readonly constraint

function factory_55033_2<const T extends unknown[]>(cb: (...args: T) => void) {
>factory_55033_2 : Symbol(factory_55033_2, Decl(typeParameterConstModifiers.ts, 123, 2))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 127, 25))
>cb : Symbol(cb, Decl(typeParameterConstModifiers.ts, 127, 52))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 127, 57))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 127, 25))

return function call<const K extends T>(...args: K): K {
>call : Symbol(call, Decl(typeParameterConstModifiers.ts, 128, 10))
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 127, 25))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 128, 44))
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))

return {} as K;
>K : Symbol(K, Decl(typeParameterConstModifiers.ts, 128, 25))

};
}

const t1_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
>t1_55033_2 : Symbol(t1_55033_2, Decl(typeParameterConstModifiers.ts, 133, 5))
>factory_55033_2 : Symbol(factory_55033_2, Decl(typeParameterConstModifiers.ts, 123, 2))
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 133, 36))
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 133, 40))
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 133, 56))

{ test: 123 },
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 134, 5))

"some string"
);

const t2_55033_2 = factory_55033_2((a: { test: number }, b: string) => {})(
>t2_55033_2 : Symbol(t2_55033_2, Decl(typeParameterConstModifiers.ts, 138, 5))
>factory_55033_2 : Symbol(factory_55033_2, Decl(typeParameterConstModifiers.ts, 123, 2))
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 138, 36))
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 138, 40))
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 138, 56))

{ test: 123 } as const,
>test : Symbol(test, Decl(typeParameterConstModifiers.ts, 139, 5))
>const : Symbol(const)

"some string"
);

// Repro from https://github.com/microsoft/TypeScript/issues/51931

declare function fn<const T extends any[]>(...args: T): T;
>fn : Symbol(fn, Decl(typeParameterConstModifiers.ts, 141, 2))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 145, 20))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 145, 43))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 145, 20))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 145, 20))

const a = fn("a", false);
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 147, 5))
>fn : Symbol(fn, Decl(typeParameterConstModifiers.ts, 141, 2))

// More examples of non-readonly constraints

declare function fa1<const T extends unknown[]>(args: T): T;
>fa1 : Symbol(fa1, Decl(typeParameterConstModifiers.ts, 147, 25))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 151, 21))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 151, 48))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 151, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 151, 21))

declare function fa2<const T extends readonly unknown[]>(args: T): T;
>fa2 : Symbol(fa2, Decl(typeParameterConstModifiers.ts, 151, 60))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 152, 21))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 152, 57))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 152, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 152, 21))

fa1(["hello", 42]);
>fa1 : Symbol(fa1, Decl(typeParameterConstModifiers.ts, 147, 25))

fa2(["hello", 42]);
>fa2 : Symbol(fa2, Decl(typeParameterConstModifiers.ts, 151, 60))

declare function fb1<const T extends unknown[]>(...args: T): T;
>fb1 : Symbol(fb1, Decl(typeParameterConstModifiers.ts, 155, 19))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 157, 21))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 157, 48))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 157, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 157, 21))

declare function fb2<const T extends readonly unknown[]>(...args: T): T;
>fb2 : Symbol(fb2, Decl(typeParameterConstModifiers.ts, 157, 63))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 158, 21))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 158, 57))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 158, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 158, 21))

fb1("hello", 42);
>fb1 : Symbol(fb1, Decl(typeParameterConstModifiers.ts, 155, 19))

fb2("hello", 42);
>fb2 : Symbol(fb2, Decl(typeParameterConstModifiers.ts, 157, 63))

declare function fc1<const T extends unknown[]>(f: (...args: T) => void, ...args: T): T;
>fc1 : Symbol(fc1, Decl(typeParameterConstModifiers.ts, 161, 17))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))
>f : Symbol(f, Decl(typeParameterConstModifiers.ts, 163, 48))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 163, 52))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 163, 72))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 163, 21))

declare function fc2<const T extends readonly unknown[]>(f: (...args: T) => void, ...args: T): T;
>fc2 : Symbol(fc2, Decl(typeParameterConstModifiers.ts, 163, 88))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))
>f : Symbol(f, Decl(typeParameterConstModifiers.ts, 164, 57))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 164, 61))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 164, 81))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 164, 21))

fc1((a: string, b: number) => {}, "hello", 42);
>fc1 : Symbol(fc1, Decl(typeParameterConstModifiers.ts, 161, 17))
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 166, 5))
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 166, 15))

fc2((a: string, b: number) => {}, "hello", 42);
>fc2 : Symbol(fc2, Decl(typeParameterConstModifiers.ts, 163, 88))
>a : Symbol(a, Decl(typeParameterConstModifiers.ts, 167, 5))
>b : Symbol(b, Decl(typeParameterConstModifiers.ts, 167, 15))

declare function fn1<const T extends { foo: unknown[] }[]>(...args: T): T;
>fn1 : Symbol(fn1, Decl(typeParameterConstModifiers.ts, 167, 47))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 169, 38))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 169, 59))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))

fn1({ foo: ["hello", 123] }, { foo: [true]});
>fn1 : Symbol(fn1, Decl(typeParameterConstModifiers.ts, 167, 47))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 171, 5))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 171, 30))

Loading

0 comments on commit f6833cd

Please sign in to comment.