-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Revert PR 55371 #58702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Revert PR 55371 #58702
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/baselines/reference/templateLiteralTypes5.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
templateLiteralTypes5.ts(10,7): error TS2322: Type '<T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]' is not assignable to type 'F2'. | ||
Type 'TypeMap[T2]' is not assignable to type 'TypeMap[`${T2}`]'. | ||
Type 'T2' is not assignable to type '`${T2}`'. | ||
Type '"a" | "b"' is not assignable to type '`${T2}`'. | ||
Type '"a"' is not assignable to type '`${T2}`'. | ||
templateLiteralTypes5.ts(13,11): error TS2322: Type 'T3' is not assignable to type '`${T3}`'. | ||
Type '"a" | "b"' is not assignable to type '`${T3}`'. | ||
Type '"a"' is not assignable to type '`${T3}`'. | ||
templateLiteralTypes5.ts(14,11): error TS2322: Type '`${T3}`' is not assignable to type 'T3'. | ||
'`${T3}`' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'. | ||
Type '"a" | "b"' is not assignable to type 'T3'. | ||
'"a" | "b"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'. | ||
Type '"a"' is not assignable to type 'T3'. | ||
'"a"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'. | ||
|
||
|
||
==== templateLiteralTypes5.ts (3 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/55364 | ||
interface TypeMap { | ||
a: "A"; | ||
b: "B"; | ||
} | ||
declare const f: <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]; | ||
type F1 = <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1]; | ||
const f1: F1 = f; | ||
type F2 = <T2 extends 'a' | 'b'>(x: `${T2}`) => TypeMap[`${T2}`] | ||
const f2: F2 = f | ||
~~ | ||
!!! error TS2322: Type '<T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]' is not assignable to type 'F2'. | ||
!!! error TS2322: Type 'TypeMap[T2]' is not assignable to type 'TypeMap[`${T2}`]'. | ||
!!! error TS2322: Type 'T2' is not assignable to type '`${T2}`'. | ||
!!! error TS2322: Type '"a" | "b"' is not assignable to type '`${T2}`'. | ||
!!! error TS2322: Type '"a"' is not assignable to type '`${T2}`'. | ||
|
||
function f3<T3 extends "a" | "b">(x: T3) { | ||
const test1: `${T3}` = x | ||
~~~~~ | ||
!!! error TS2322: Type 'T3' is not assignable to type '`${T3}`'. | ||
!!! error TS2322: Type '"a" | "b"' is not assignable to type '`${T3}`'. | ||
!!! error TS2322: Type '"a"' is not assignable to type '`${T3}`'. | ||
const test2: T3 = "" as `${T3}`; | ||
~~~~~ | ||
!!! error TS2322: Type '`${T3}`' is not assignable to type 'T3'. | ||
!!! error TS2322: '`${T3}`' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'. | ||
!!! error TS2322: Type '"a" | "b"' is not assignable to type 'T3'. | ||
!!! error TS2322: '"a" | "b"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'. | ||
!!! error TS2322: Type '"a"' is not assignable to type 'T3'. | ||
!!! error TS2322: '"a"' is assignable to the constraint of type 'T3', but 'T3' could be instantiated with a different subtype of constraint '"a" | "b"'. | ||
} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add an extra test case to the original test file here based on Anders' comment in the other PR: declare function bar<T extends string>(x: `${T}`): T;
function baz<U extends string>(x: `${U}`) {
return bar(x);
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//// [tests/cases/conformance/types/literal/templateLiteralTypes8.ts] //// | ||
|
||
=== templateLiteralTypes8.ts === | ||
const enum E { | ||
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0)) | ||
|
||
a = "a", | ||
>a : Symbol(E.a, Decl(templateLiteralTypes8.ts, 0, 14)) | ||
|
||
b = "b", | ||
>b : Symbol(E.b, Decl(templateLiteralTypes8.ts, 1, 10)) | ||
} | ||
|
||
type Stringify<T extends string> = `${T}`; | ||
>Stringify : Symbol(Stringify, Decl(templateLiteralTypes8.ts, 3, 1)) | ||
>T : Symbol(T, Decl(templateLiteralTypes8.ts, 5, 15)) | ||
>T : Symbol(T, Decl(templateLiteralTypes8.ts, 5, 15)) | ||
|
||
let z1: `${E}` = "a"; | ||
>z1 : Symbol(z1, Decl(templateLiteralTypes8.ts, 7, 3)) | ||
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0)) | ||
|
||
let z2: Stringify<E> = "a"; | ||
>z2 : Symbol(z2, Decl(templateLiteralTypes8.ts, 8, 3)) | ||
>Stringify : Symbol(Stringify, Decl(templateLiteralTypes8.ts, 3, 1)) | ||
>E : Symbol(E, Decl(templateLiteralTypes8.ts, 0, 0)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//// [tests/cases/conformance/types/literal/templateLiteralTypes8.ts] //// | ||
|
||
=== templateLiteralTypes8.ts === | ||
const enum E { | ||
>E : E | ||
> : ^ | ||
|
||
a = "a", | ||
>a : E.a | ||
> : ^^^ | ||
>"a" : "a" | ||
> : ^^^ | ||
|
||
b = "b", | ||
>b : E.b | ||
> : ^^^ | ||
>"b" : "b" | ||
> : ^^^ | ||
} | ||
|
||
type Stringify<T extends string> = `${T}`; | ||
>Stringify : `${T}` | ||
> : ^^^^^^ | ||
|
||
let z1: `${E}` = "a"; | ||
>z1 : "a" | "b" | ||
> : ^^^^^^^^^ | ||
>"a" : "a" | ||
> : ^^^ | ||
|
||
let z2: Stringify<E> = "a"; | ||
>z2 : "a" | "b" | ||
> : ^^^^^^^^^ | ||
>"a" : "a" | ||
> : ^^^ | ||
|
12 changes: 12 additions & 0 deletions
12
tests/cases/conformance/types/literal/templateLiteralTypes8.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
const enum E { | ||
a = "a", | ||
b = "b", | ||
} | ||
|
||
type Stringify<T extends string> = `${T}`; | ||
|
||
let z1: `${E}` = "a"; | ||
let z2: Stringify<E> = "a"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be nice to add comments to both of those assignments to explain the error, like: