-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Reduce template literal types with a single placeholder and no extra texts #55371
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
gabritto
merged 6 commits into
microsoft:main
from
Andarist:fix/template-literal-type-with-no-texts-relations
Mar 14, 2024
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12dbb98
Improved relationship checking for template literal types with a sing…
Andarist d6fe15f
Merge remote-tracking branch 'origin/main' into fix/template-literal-…
Andarist 7a4bc1b
Merge remote-tracking branch 'origin/main' into fix/template-literal-…
Andarist c978136
Unwrap eagerly
Andarist aac8961
Move check
Andarist 6d63a94
Merge remote-tracking branch 'origin/main' into fix/template-literal-…
Andarist 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//// [tests/cases/conformance/types/literal/templateLiteralTypes5.ts] //// | ||
|
||
=== templateLiteralTypes5.ts === | ||
// https://github.com/microsoft/TypeScript/issues/55364 | ||
interface TypeMap { | ||
>TypeMap : Symbol(TypeMap, Decl(templateLiteralTypes5.ts, 0, 0)) | ||
|
||
a: "A"; | ||
>a : Symbol(TypeMap.a, Decl(templateLiteralTypes5.ts, 1, 19)) | ||
|
||
b: "B"; | ||
>b : Symbol(TypeMap.b, Decl(templateLiteralTypes5.ts, 2, 9)) | ||
} | ||
declare const f: <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]; | ||
>f : Symbol(f, Decl(templateLiteralTypes5.ts, 5, 13)) | ||
>T0 : Symbol(T0, Decl(templateLiteralTypes5.ts, 5, 18)) | ||
>x : Symbol(x, Decl(templateLiteralTypes5.ts, 5, 40)) | ||
>T0 : Symbol(T0, Decl(templateLiteralTypes5.ts, 5, 18)) | ||
>TypeMap : Symbol(TypeMap, Decl(templateLiteralTypes5.ts, 0, 0)) | ||
>T0 : Symbol(T0, Decl(templateLiteralTypes5.ts, 5, 18)) | ||
|
||
type F1 = <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1]; | ||
>F1 : Symbol(F1, Decl(templateLiteralTypes5.ts, 5, 67)) | ||
>T1 : Symbol(T1, Decl(templateLiteralTypes5.ts, 6, 11)) | ||
>x : Symbol(x, Decl(templateLiteralTypes5.ts, 6, 33)) | ||
>T1 : Symbol(T1, Decl(templateLiteralTypes5.ts, 6, 11)) | ||
>TypeMap : Symbol(TypeMap, Decl(templateLiteralTypes5.ts, 0, 0)) | ||
>T1 : Symbol(T1, Decl(templateLiteralTypes5.ts, 6, 11)) | ||
|
||
const f1: F1 = f; | ||
>f1 : Symbol(f1, Decl(templateLiteralTypes5.ts, 7, 5)) | ||
>F1 : Symbol(F1, Decl(templateLiteralTypes5.ts, 5, 67)) | ||
>f : Symbol(f, Decl(templateLiteralTypes5.ts, 5, 13)) | ||
|
||
type F2 = <T2 extends 'a' | 'b'>(x: `${T2}`) => TypeMap[`${T2}`] | ||
>F2 : Symbol(F2, Decl(templateLiteralTypes5.ts, 7, 17)) | ||
>T2 : Symbol(T2, Decl(templateLiteralTypes5.ts, 8, 11)) | ||
>x : Symbol(x, Decl(templateLiteralTypes5.ts, 8, 33)) | ||
>T2 : Symbol(T2, Decl(templateLiteralTypes5.ts, 8, 11)) | ||
>TypeMap : Symbol(TypeMap, Decl(templateLiteralTypes5.ts, 0, 0)) | ||
>T2 : Symbol(T2, Decl(templateLiteralTypes5.ts, 8, 11)) | ||
|
||
const f2: F2 = f | ||
>f2 : Symbol(f2, Decl(templateLiteralTypes5.ts, 9, 5)) | ||
>F2 : Symbol(F2, Decl(templateLiteralTypes5.ts, 7, 17)) | ||
>f : Symbol(f, Decl(templateLiteralTypes5.ts, 5, 13)) | ||
|
||
function f3<T3 extends "a" | "b">(x: T3) { | ||
>f3 : Symbol(f3, Decl(templateLiteralTypes5.ts, 9, 16)) | ||
>T3 : Symbol(T3, Decl(templateLiteralTypes5.ts, 11, 12)) | ||
>x : Symbol(x, Decl(templateLiteralTypes5.ts, 11, 34)) | ||
>T3 : Symbol(T3, Decl(templateLiteralTypes5.ts, 11, 12)) | ||
|
||
const test1: `${T3}` = x | ||
>test1 : Symbol(test1, Decl(templateLiteralTypes5.ts, 12, 9)) | ||
>T3 : Symbol(T3, Decl(templateLiteralTypes5.ts, 11, 12)) | ||
>x : Symbol(x, Decl(templateLiteralTypes5.ts, 11, 34)) | ||
|
||
const test2: T3 = "" as `${T3}`; | ||
>test2 : Symbol(test2, Decl(templateLiteralTypes5.ts, 13, 9)) | ||
>T3 : Symbol(T3, Decl(templateLiteralTypes5.ts, 11, 12)) | ||
>T3 : Symbol(T3, Decl(templateLiteralTypes5.ts, 11, 12)) | ||
} | ||
|
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,45 @@ | ||
//// [tests/cases/conformance/types/literal/templateLiteralTypes5.ts] //// | ||
|
||
=== templateLiteralTypes5.ts === | ||
// https://github.com/microsoft/TypeScript/issues/55364 | ||
interface TypeMap { | ||
a: "A"; | ||
>a : "A" | ||
|
||
b: "B"; | ||
>b : "B" | ||
} | ||
declare const f: <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0]; | ||
>f : <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0] | ||
>x : `${T0}` | ||
|
||
type F1 = <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1]; | ||
>F1 : <T1 extends "a" | "b">(x: `${T1}`) => TypeMap[T1] | ||
>x : `${T1}` | ||
|
||
const f1: F1 = f; | ||
>f1 : F1 | ||
>f : <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0] | ||
|
||
type F2 = <T2 extends 'a' | 'b'>(x: `${T2}`) => TypeMap[`${T2}`] | ||
>F2 : <T2 extends "a" | "b">(x: `${T2}`) => TypeMap[`${T2}`] | ||
>x : `${T2}` | ||
|
||
const f2: F2 = f | ||
>f2 : F2 | ||
>f : <T0 extends "a" | "b">(x: `${T0}`) => TypeMap[T0] | ||
|
||
function f3<T3 extends "a" | "b">(x: T3) { | ||
>f3 : <T3 extends "a" | "b">(x: T3) => void | ||
>x : T3 | ||
|
||
const test1: `${T3}` = x | ||
>test1 : `${T3}` | ||
>x : T3 | ||
|
||
const test2: T3 = "" as `${T3}`; | ||
>test2 : T3 | ||
>"" as `${T3}` : `${T3}` | ||
>"" : "" | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
tests/cases/conformance/types/literal/templateLiteralTypes5.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,19 @@ | ||
// @strict: true | ||
// @target: esnext | ||
// @noEmit: true | ||
|
||
// 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 | ||
|
||
function f3<T3 extends "a" | "b">(x: T3) { | ||
const test1: `${T3}` = x | ||
const test2: T3 = "" as `${T3}`; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.