Skip to content

Commit 28c1b3a

Browse files
committed
Add tests
1 parent 90d868a commit 28c1b3a

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

tests/baselines/reference/genericRestTypes.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,24 @@ type Explicit = (...args: Tail<Parameters<MyFunctionType>>) => ReturnType<MyFunc
1111

1212
type Bind1<T extends (head: any, ...tail: any[]) => any> = (...args: Tail<Parameters<T>>) => ReturnType<T>;
1313
type Generic = Bind1<MyFunctionType>; // (bar: string) => boolean
14+
15+
function assignmentWithComplexRest<T extends any[]>() {
16+
const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
17+
const fn2: (...args: never) => void = fn1;
18+
type Fn2Ret = ReturnType<typeof fn2>;
19+
}
1420

1521

1622
//// [genericRestTypes.js]
1723
"use strict";
1824
// Repro from #25793
25+
function assignmentWithComplexRest() {
26+
var fn1 = function (x) {
27+
var _ = [];
28+
for (var _i = 1; _i < arguments.length; _i++) {
29+
_[_i - 1] = arguments[_i];
30+
}
31+
return x;
32+
};
33+
var fn2 = fn1;
34+
}

tests/baselines/reference/genericRestTypes.symbols

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,27 @@ type Generic = Bind1<MyFunctionType>; // (bar: string) => boolean
4444
>Bind1 : Symbol(Bind1, Decl(genericRestTypes.ts, 8, 90))
4545
>MyFunctionType : Symbol(MyFunctionType, Decl(genericRestTypes.ts, 4, 110))
4646

47+
function assignmentWithComplexRest<T extends any[]>() {
48+
>assignmentWithComplexRest : Symbol(assignmentWithComplexRest, Decl(genericRestTypes.ts, 11, 37))
49+
>T : Symbol(T, Decl(genericRestTypes.ts, 13, 35))
50+
51+
const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
52+
>fn1 : Symbol(fn1, Decl(genericRestTypes.ts, 14, 9))
53+
>x : Symbol(x, Decl(genericRestTypes.ts, 14, 16))
54+
>rest : Symbol(rest, Decl(genericRestTypes.ts, 14, 26))
55+
>T : Symbol(T, Decl(genericRestTypes.ts, 13, 35))
56+
>x : Symbol(x, Decl(genericRestTypes.ts, 14, 50))
57+
>_ : Symbol(_, Decl(genericRestTypes.ts, 14, 52))
58+
>x : Symbol(x, Decl(genericRestTypes.ts, 14, 50))
59+
60+
const fn2: (...args: never) => void = fn1;
61+
>fn2 : Symbol(fn2, Decl(genericRestTypes.ts, 15, 9))
62+
>args : Symbol(args, Decl(genericRestTypes.ts, 15, 16))
63+
>fn1 : Symbol(fn1, Decl(genericRestTypes.ts, 14, 9))
64+
65+
type Fn2Ret = ReturnType<typeof fn2>;
66+
>Fn2Ret : Symbol(Fn2Ret, Decl(genericRestTypes.ts, 15, 46))
67+
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --))
68+
>fn2 : Symbol(fn2, Decl(genericRestTypes.ts, 15, 9))
69+
}
70+

tests/baselines/reference/genericRestTypes.types

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,25 @@ type Bind1<T extends (head: any, ...tail: any[]) => any> = (...args: Tail<Parame
2727
type Generic = Bind1<MyFunctionType>; // (bar: string) => boolean
2828
>Generic : Bind1<MyFunctionType>
2929

30+
function assignmentWithComplexRest<T extends any[]>() {
31+
>assignmentWithComplexRest : <T extends any[]>() => void
32+
33+
const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
34+
>fn1 : (x: string, ...rest: T) => void
35+
>x : string
36+
>rest : T
37+
>(x, ..._) => x : (x: string, ..._: T) => string
38+
>x : string
39+
>_ : T
40+
>x : string
41+
42+
const fn2: (...args: never) => void = fn1;
43+
>fn2 : (...args: never) => void
44+
>args : never
45+
>fn1 : (x: string, ...rest: T) => void
46+
47+
type Fn2Ret = ReturnType<typeof fn2>;
48+
>Fn2Ret : void
49+
>fn2 : (...args: never) => void
50+
}
51+

tests/cases/compiler/genericRestTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ type Explicit = (...args: Tail<Parameters<MyFunctionType>>) => ReturnType<MyFunc
1212

1313
type Bind1<T extends (head: any, ...tail: any[]) => any> = (...args: Tail<Parameters<T>>) => ReturnType<T>;
1414
type Generic = Bind1<MyFunctionType>; // (bar: string) => boolean
15+
16+
function assignmentWithComplexRest<T extends any[]>() {
17+
const fn1: (x: string, ...rest: T) => void = (x, ..._) => x;
18+
const fn2: (...args: never) => void = fn1;
19+
type Fn2Ret = ReturnType<typeof fn2>;
20+
}

0 commit comments

Comments
 (0)