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 3, 2023
1 parent 52fe112 commit f1104cc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ typeParameterConstModifiers.ts(55,9): error TS1277: 'const' modifier can only ap
fc1((a: string, b: number) => {}, "hello", 42);
fc2((a: string, b: number) => {}, "hello", 42);

declare function fd1<const T extends string[] | number[]>(args: T): T;
declare function fd2<const T extends readonly string[] | readonly number[]>(args: T): T;

fd1(["hello", "world"]);
fd1([1, 2, 3]);
fd2(["hello", "world"]);
fd2([1, 2, 3]);

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

fn1({ foo: ["hello", 123] }, { foo: [true]});
Expand Down
12 changes: 12 additions & 0 deletions tests/baselines/reference/typeParameterConstModifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ declare function fc2<const T extends readonly unknown[]>(f: (...args: T) => void
fc1((a: string, b: number) => {}, "hello", 42);
fc2((a: string, b: number) => {}, "hello", 42);

declare function fd1<const T extends string[] | number[]>(args: T): T;
declare function fd2<const T extends readonly string[] | readonly number[]>(args: T): T;

fd1(["hello", "world"]);
fd1([1, 2, 3]);
fd2(["hello", "world"]);
fd2([1, 2, 3]);

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

fn1({ foo: ["hello", 123] }, { foo: [true]});
Expand Down Expand Up @@ -261,4 +269,8 @@ fb1("hello", 42);
fb2("hello", 42);
fc1(function (a, b) { }, "hello", 42);
fc2(function (a, b) { }, "hello", 42);
fd1(["hello", "world"]);
fd1([1, 2, 3]);
fd2(["hello", "world"]);
fd2([1, 2, 3]);
fn1({ foo: ["hello", 123] }, { foo: [true] });
40 changes: 33 additions & 7 deletions tests/baselines/reference/typeParameterConstModifiers.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -562,16 +562,42 @@ fc2((a: string, b: number) => {}, "hello", 42);
>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))
declare function fd1<const T extends string[] | number[]>(args: T): T;
>fd1 : Symbol(fd1, 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))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 169, 58))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 169, 21))

declare function fd2<const T extends readonly string[] | readonly number[]>(args: T): T;
>fd2 : Symbol(fd2, Decl(typeParameterConstModifiers.ts, 169, 70))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 170, 21))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 170, 76))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 170, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 170, 21))

fd1(["hello", "world"]);
>fd1 : Symbol(fd1, Decl(typeParameterConstModifiers.ts, 167, 47))

fd1([1, 2, 3]);
>fd1 : Symbol(fd1, Decl(typeParameterConstModifiers.ts, 167, 47))

fd2(["hello", "world"]);
>fd2 : Symbol(fd2, Decl(typeParameterConstModifiers.ts, 169, 70))

fd2([1, 2, 3]);
>fd2 : Symbol(fd2, Decl(typeParameterConstModifiers.ts, 169, 70))

declare function fn1<const T extends { foo: unknown[] }[]>(...args: T): T;
>fn1 : Symbol(fn1, Decl(typeParameterConstModifiers.ts, 175, 15))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 177, 21))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 177, 38))
>args : Symbol(args, Decl(typeParameterConstModifiers.ts, 177, 59))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 177, 21))
>T : Symbol(T, Decl(typeParameterConstModifiers.ts, 177, 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))
>fn1 : Symbol(fn1, Decl(typeParameterConstModifiers.ts, 175, 15))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 179, 5))
>foo : Symbol(foo, Decl(typeParameterConstModifiers.ts, 179, 30))

38 changes: 38 additions & 0 deletions tests/baselines/reference/typeParameterConstModifiers.types
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,44 @@ fc2((a: string, b: number) => {}, "hello", 42);
>"hello" : "hello"
>42 : 42

declare function fd1<const T extends string[] | number[]>(args: T): T;
>fd1 : <const T extends string[] | number[]>(args: T) => T
>args : T

declare function fd2<const T extends readonly string[] | readonly number[]>(args: T): T;
>fd2 : <const T extends readonly string[] | readonly number[]>(args: T) => T
>args : T

fd1(["hello", "world"]);
>fd1(["hello", "world"]) : ["hello", "world"]
>fd1 : <const T extends string[] | number[]>(args: T) => T
>["hello", "world"] : ["hello", "world"]
>"hello" : "hello"
>"world" : "world"

fd1([1, 2, 3]);
>fd1([1, 2, 3]) : [1, 2, 3]
>fd1 : <const T extends string[] | number[]>(args: T) => T
>[1, 2, 3] : [1, 2, 3]
>1 : 1
>2 : 2
>3 : 3

fd2(["hello", "world"]);
>fd2(["hello", "world"]) : readonly ["hello", "world"]
>fd2 : <const T extends readonly string[] | readonly number[]>(args: T) => T
>["hello", "world"] : ["hello", "world"]
>"hello" : "hello"
>"world" : "world"

fd2([1, 2, 3]);
>fd2([1, 2, 3]) : readonly [1, 2, 3]
>fd2 : <const T extends readonly string[] | readonly number[]>(args: T) => T
>[1, 2, 3] : [1, 2, 3]
>1 : 1
>2 : 2
>3 : 3

declare function fn1<const T extends { foo: unknown[] }[]>(...args: T): T;
>fn1 : <const T extends { foo: unknown[]; }[]>(...args: T) => T
>foo : unknown[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ declare function fc2<const T extends readonly unknown[]>(f: (...args: T) => void
fc1((a: string, b: number) => {}, "hello", 42);
fc2((a: string, b: number) => {}, "hello", 42);

declare function fd1<const T extends string[] | number[]>(args: T): T;
declare function fd2<const T extends readonly string[] | readonly number[]>(args: T): T;

fd1(["hello", "world"]);
fd1([1, 2, 3]);
fd2(["hello", "world"]);
fd2([1, 2, 3]);

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

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

0 comments on commit f1104cc

Please sign in to comment.