Add regression test

This commit is contained in:
Anders Hejlsberg 2021-11-11 05:50:27 -10:00
parent 26a626d045
commit fb93b181ff
5 changed files with 130 additions and 0 deletions

View file

@ -198,4 +198,17 @@ tests/cases/conformance/types/literal/templateLiteralTypes3.ts(141,9): error TS2
action.response;
}
}
// Repro from #46768
type DotString = `${string}.${string}.${string}`;
declare function noSpread<P extends DotString>(args: P[]): P;
declare function spread<P extends DotString>(...args: P[]): P;
noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
spread(`1.${'2'}.3`, `1.${'2'}.4`);
spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);

View file

@ -170,6 +170,19 @@ function reducer(action: Action) {
action.response;
}
}
// Repro from #46768
type DotString = `${string}.${string}.${string}`;
declare function noSpread<P extends DotString>(args: P[]): P;
declare function spread<P extends DotString>(...args: P[]): P;
noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
spread(`1.${'2'}.3`, `1.${'2'}.4`);
spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
//// [templateLiteralTypes3.js]
@ -257,6 +270,10 @@ function reducer(action) {
action.response;
}
}
noSpread(["1.".concat('2', ".3"), "1.".concat('2', ".4")]);
noSpread(["1.".concat('2', ".3"), "1.".concat('2', ".4")]);
spread("1.".concat('2', ".3"), "1.".concat('2', ".4"));
spread("1.".concat('2', ".3"), "1.".concat('2', ".4"));
//// [templateLiteralTypes3.d.ts]
@ -324,3 +341,6 @@ declare type Action = {
response: string;
};
declare function reducer(action: Action): void;
declare type DotString = `${string}.${string}.${string}`;
declare function noSpread<P extends DotString>(args: P[]): P;
declare function spread<P extends DotString>(...args: P[]): P;

View file

@ -516,3 +516,36 @@ function reducer(action: Action) {
}
}
// Repro from #46768
type DotString = `${string}.${string}.${string}`;
>DotString : Symbol(DotString, Decl(templateLiteralTypes3.ts, 170, 1))
declare function noSpread<P extends DotString>(args: P[]): P;
>noSpread : Symbol(noSpread, Decl(templateLiteralTypes3.ts, 174, 49))
>P : Symbol(P, Decl(templateLiteralTypes3.ts, 176, 26))
>DotString : Symbol(DotString, Decl(templateLiteralTypes3.ts, 170, 1))
>args : Symbol(args, Decl(templateLiteralTypes3.ts, 176, 47))
>P : Symbol(P, Decl(templateLiteralTypes3.ts, 176, 26))
>P : Symbol(P, Decl(templateLiteralTypes3.ts, 176, 26))
declare function spread<P extends DotString>(...args: P[]): P;
>spread : Symbol(spread, Decl(templateLiteralTypes3.ts, 176, 61))
>P : Symbol(P, Decl(templateLiteralTypes3.ts, 177, 24))
>DotString : Symbol(DotString, Decl(templateLiteralTypes3.ts, 170, 1))
>args : Symbol(args, Decl(templateLiteralTypes3.ts, 177, 45))
>P : Symbol(P, Decl(templateLiteralTypes3.ts, 177, 24))
>P : Symbol(P, Decl(templateLiteralTypes3.ts, 177, 24))
noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
>noSpread : Symbol(noSpread, Decl(templateLiteralTypes3.ts, 174, 49))
noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
>noSpread : Symbol(noSpread, Decl(templateLiteralTypes3.ts, 174, 49))
spread(`1.${'2'}.3`, `1.${'2'}.4`);
>spread : Symbol(spread, Decl(templateLiteralTypes3.ts, 176, 61))
spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
>spread : Symbol(spread, Decl(templateLiteralTypes3.ts, 176, 61))

View file

@ -513,3 +513,54 @@ function reducer(action: Action) {
}
}
// Repro from #46768
type DotString = `${string}.${string}.${string}`;
>DotString : `${string}.${string}.${string}`
declare function noSpread<P extends DotString>(args: P[]): P;
>noSpread : <P extends `${string}.${string}.${string}`>(args: P[]) => P
>args : P[]
declare function spread<P extends DotString>(...args: P[]): P;
>spread : <P extends `${string}.${string}.${string}`>(...args: P[]) => P
>args : P[]
noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
>noSpread([`1.${'2'}.3`, `1.${'2'}.4`]) : "1.2.3" | "1.2.4"
>noSpread : <P extends `${string}.${string}.${string}`>(args: P[]) => P
>[`1.${'2'}.3`, `1.${'2'}.4`] : ("1.2.3" | "1.2.4")[]
>`1.${'2'}.3` : "1.2.3"
>'2' : "2"
>`1.${'2'}.4` : "1.2.4"
>'2' : "2"
noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
>noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]) : `1.${string}.3` | `1.${string}.4`
>noSpread : <P extends `${string}.${string}.${string}`>(args: P[]) => P
>[`1.${'2' as string}.3`, `1.${'2' as string}.4`] : (`1.${string}.3` | `1.${string}.4`)[]
>`1.${'2' as string}.3` : `1.${string}.3`
>'2' as string : string
>'2' : "2"
>`1.${'2' as string}.4` : `1.${string}.4`
>'2' as string : string
>'2' : "2"
spread(`1.${'2'}.3`, `1.${'2'}.4`);
>spread(`1.${'2'}.3`, `1.${'2'}.4`) : "1.2.3" | "1.2.4"
>spread : <P extends `${string}.${string}.${string}`>(...args: P[]) => P
>`1.${'2'}.3` : "1.2.3"
>'2' : "2"
>`1.${'2'}.4` : "1.2.4"
>'2' : "2"
spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);
>spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`) : `1.${string}.3` | `1.${string}.4`
>spread : <P extends `${string}.${string}.${string}`>(...args: P[]) => P
>`1.${'2' as string}.3` : `1.${string}.3`
>'2' as string : string
>'2' : "2"
>`1.${'2' as string}.4` : `1.${string}.4`
>'2' as string : string
>'2' : "2"

View file

@ -172,3 +172,16 @@ function reducer(action: Action) {
action.response;
}
}
// Repro from #46768
type DotString = `${string}.${string}.${string}`;
declare function noSpread<P extends DotString>(args: P[]): P;
declare function spread<P extends DotString>(...args: P[]): P;
noSpread([`1.${'2'}.3`, `1.${'2'}.4`]);
noSpread([`1.${'2' as string}.3`, `1.${'2' as string}.4`]);
spread(`1.${'2'}.3`, `1.${'2'}.4`);
spread(`1.${'2' as string}.3`, `1.${'2' as string}.4`);