-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Revert fix for intersections in template literals, fix differently #52836
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
+359
−27
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0c18a81
Add test
jakebailey 1dd84d2
Add new test
jakebailey 8b1f1e5
Revert PR 48044
jakebailey bb599af
Implement new fix for intersections
jakebailey 1f07f63
Remove TODO
jakebailey 8528a63
Add new failing test from top100
jakebailey 8d55d27
Add objectFlags to TemplateLiteral in order to propagate generic-ness
jakebailey 0e048db
Add new test, showing bad interaction of StringMapping
jakebailey 7d38709
Handle intersections in getStringMappingType
jakebailey 84a7a10
Add to ObjectFlagsType, but I'm not sure I like this
jakebailey 014bf02
Merge branch 'main' into fix-52345
jakebailey 026cd53
PR feedback maybe
jakebailey 27ae967
Merge branch 'main' into fix-52345
jakebailey 15e3676
PR feedback
jakebailey 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
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/deeplyNestedTemplateLiteralIntersection.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,29 @@ | ||
| tests/cases/compiler/deeplyNestedTemplateLiteralIntersection.ts(20,11): error TS2590: Expression produces a union type that is too complex to represent. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/deeplyNestedTemplateLiteralIntersection.ts (1 errors) ==== | ||
| type R = `${number}a` & { | ||
| _thing: true; | ||
| }; | ||
|
|
||
| type _S = "1" | "2" | "3" | "4" | "5" | "6"; | ||
|
|
||
| type S = `${_S}${_S}${_S}`; | ||
|
|
||
|
|
||
| type T = R | S; | ||
| type X = `${T} ${T}`; | ||
|
|
||
| export type Props = Partial<{ | ||
| x: X; | ||
| }>; | ||
|
|
||
| const a1: Props = {}; | ||
| const a2: Props = {}; | ||
|
|
||
| const b = { ...a1, ...a2 }; | ||
| ~~~~~~~~~~~~~~~~ | ||
| !!! error TS2590: Expression produces a union type that is too complex to represent. | ||
|
|
||
| export { b }; | ||
|
|
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
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/templateLiteralIntersection2.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,41 @@ | ||
| tests/cases/compiler/templateLiteralIntersection2.ts(7,12): error TS2345: Argument of type '"foo/bar"' is not assignable to parameter of type '`${Path}/${Path}`'. | ||
| tests/cases/compiler/templateLiteralIntersection2.ts(20,10): error TS2345: Argument of type '""' is not assignable to parameter of type '`a${string}` & `${string}a`'. | ||
| Type '""' is not assignable to type '`a${string}`'. | ||
| tests/cases/compiler/templateLiteralIntersection2.ts(22,10): error TS2345: Argument of type '"ab"' is not assignable to parameter of type '`a${string}` & `${string}a`'. | ||
| Type '"ab"' is not assignable to type '`${string}a`'. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/templateLiteralIntersection2.ts (3 errors) ==== | ||
| type Path = string & { _pathBrand: any }; | ||
|
|
||
| type JoinedPath = `${Path}/${Path}`; | ||
|
|
||
| declare function joinedPath(p: JoinedPath): void; | ||
|
|
||
| joinedPath("foo/bar"); | ||
| ~~~~~~~~~ | ||
| !!! error TS2345: Argument of type '"foo/bar"' is not assignable to parameter of type '`${Path}/${Path}`'. | ||
|
|
||
| declare const somePath: Path; | ||
|
|
||
| joinedPath(`${somePath}/${somePath}`); | ||
|
|
||
|
|
||
| type StartsWithA = `a${string}`; | ||
| type EndsWithA = `${string}a`; | ||
|
|
||
|
|
||
| declare function withinAs(p: StartsWithA & EndsWithA): void; | ||
|
|
||
| withinAs(""); | ||
| ~~ | ||
| !!! error TS2345: Argument of type '""' is not assignable to parameter of type '`a${string}` & `${string}a`'. | ||
| !!! error TS2345: Type '""' is not assignable to type '`a${string}`'. | ||
| withinAs("a"); | ||
| withinAs("ab"); | ||
| ~~~~ | ||
| !!! error TS2345: Argument of type '"ab"' is not assignable to parameter of type '`a${string}` & `${string}a`'. | ||
| !!! error TS2345: Type '"ab"' is not assignable to type '`${string}a`'. | ||
| withinAs("aba"); | ||
| withinAs("abavvvva"); | ||
|
|
56 changes: 56 additions & 0 deletions
56
tests/baselines/reference/templateLiteralIntersection2.symbols
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,56 @@ | ||
| === tests/cases/compiler/templateLiteralIntersection2.ts === | ||
| type Path = string & { _pathBrand: any }; | ||
| >Path : Symbol(Path, Decl(templateLiteralIntersection2.ts, 0, 0)) | ||
| >_pathBrand : Symbol(_pathBrand, Decl(templateLiteralIntersection2.ts, 0, 22)) | ||
|
|
||
| type JoinedPath = `${Path}/${Path}`; | ||
| >JoinedPath : Symbol(JoinedPath, Decl(templateLiteralIntersection2.ts, 0, 41)) | ||
| >Path : Symbol(Path, Decl(templateLiteralIntersection2.ts, 0, 0)) | ||
| >Path : Symbol(Path, Decl(templateLiteralIntersection2.ts, 0, 0)) | ||
|
|
||
| declare function joinedPath(p: JoinedPath): void; | ||
| >joinedPath : Symbol(joinedPath, Decl(templateLiteralIntersection2.ts, 2, 36)) | ||
| >p : Symbol(p, Decl(templateLiteralIntersection2.ts, 4, 28)) | ||
| >JoinedPath : Symbol(JoinedPath, Decl(templateLiteralIntersection2.ts, 0, 41)) | ||
|
|
||
| joinedPath("foo/bar"); | ||
| >joinedPath : Symbol(joinedPath, Decl(templateLiteralIntersection2.ts, 2, 36)) | ||
|
|
||
| declare const somePath: Path; | ||
| >somePath : Symbol(somePath, Decl(templateLiteralIntersection2.ts, 8, 13)) | ||
| >Path : Symbol(Path, Decl(templateLiteralIntersection2.ts, 0, 0)) | ||
|
|
||
| joinedPath(`${somePath}/${somePath}`); | ||
| >joinedPath : Symbol(joinedPath, Decl(templateLiteralIntersection2.ts, 2, 36)) | ||
| >somePath : Symbol(somePath, Decl(templateLiteralIntersection2.ts, 8, 13)) | ||
| >somePath : Symbol(somePath, Decl(templateLiteralIntersection2.ts, 8, 13)) | ||
|
|
||
|
|
||
| type StartsWithA = `a${string}`; | ||
| >StartsWithA : Symbol(StartsWithA, Decl(templateLiteralIntersection2.ts, 10, 38)) | ||
|
|
||
| type EndsWithA = `${string}a`; | ||
| >EndsWithA : Symbol(EndsWithA, Decl(templateLiteralIntersection2.ts, 13, 32)) | ||
|
|
||
|
|
||
| declare function withinAs(p: StartsWithA & EndsWithA): void; | ||
| >withinAs : Symbol(withinAs, Decl(templateLiteralIntersection2.ts, 14, 30)) | ||
| >p : Symbol(p, Decl(templateLiteralIntersection2.ts, 17, 26)) | ||
| >StartsWithA : Symbol(StartsWithA, Decl(templateLiteralIntersection2.ts, 10, 38)) | ||
| >EndsWithA : Symbol(EndsWithA, Decl(templateLiteralIntersection2.ts, 13, 32)) | ||
|
|
||
| withinAs(""); | ||
| >withinAs : Symbol(withinAs, Decl(templateLiteralIntersection2.ts, 14, 30)) | ||
|
|
||
| withinAs("a"); | ||
| >withinAs : Symbol(withinAs, Decl(templateLiteralIntersection2.ts, 14, 30)) | ||
|
|
||
| withinAs("ab"); | ||
| >withinAs : Symbol(withinAs, Decl(templateLiteralIntersection2.ts, 14, 30)) | ||
|
|
||
| withinAs("aba"); | ||
| >withinAs : Symbol(withinAs, Decl(templateLiteralIntersection2.ts, 14, 30)) | ||
|
|
||
| withinAs("abavvvva"); | ||
| >withinAs : Symbol(withinAs, Decl(templateLiteralIntersection2.ts, 14, 30)) | ||
|
|
Oops, something went wrong.
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.