-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly check whether union type contains only primitive types (#46645…
…) (#46649) * Properly check whether union type contains only primitive types * Add regression test * Remove 'export' modifier from test Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
- Loading branch information
1 parent
5764cdc
commit 9b80232
Showing
6 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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,24 @@ | ||
//// [primitiveUnionDetection.ts] | ||
// Repro from #46624 | ||
|
||
type Kind = "one" | "two" | "three"; | ||
|
||
declare function getInterfaceFromString<T extends Kind>(options?: { type?: T } & { type?: Kind }): T; | ||
|
||
const result = getInterfaceFromString({ type: 'two' }); | ||
|
||
|
||
//// [primitiveUnionDetection.js] | ||
"use strict"; | ||
// Repro from #46624 | ||
var result = getInterfaceFromString({ type: 'two' }); | ||
|
||
|
||
//// [primitiveUnionDetection.d.ts] | ||
declare type Kind = "one" | "two" | "three"; | ||
declare function getInterfaceFromString<T extends Kind>(options?: { | ||
type?: T; | ||
} & { | ||
type?: Kind; | ||
}): T; | ||
declare const result: "two"; |
This file contains 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,22 @@ | ||
=== tests/cases/compiler/primitiveUnionDetection.ts === | ||
// Repro from #46624 | ||
|
||
type Kind = "one" | "two" | "three"; | ||
>Kind : Symbol(Kind, Decl(primitiveUnionDetection.ts, 0, 0)) | ||
|
||
declare function getInterfaceFromString<T extends Kind>(options?: { type?: T } & { type?: Kind }): T; | ||
>getInterfaceFromString : Symbol(getInterfaceFromString, Decl(primitiveUnionDetection.ts, 2, 36)) | ||
>T : Symbol(T, Decl(primitiveUnionDetection.ts, 4, 40)) | ||
>Kind : Symbol(Kind, Decl(primitiveUnionDetection.ts, 0, 0)) | ||
>options : Symbol(options, Decl(primitiveUnionDetection.ts, 4, 56)) | ||
>type : Symbol(type, Decl(primitiveUnionDetection.ts, 4, 67)) | ||
>T : Symbol(T, Decl(primitiveUnionDetection.ts, 4, 40)) | ||
>type : Symbol(type, Decl(primitiveUnionDetection.ts, 4, 82)) | ||
>Kind : Symbol(Kind, Decl(primitiveUnionDetection.ts, 0, 0)) | ||
>T : Symbol(T, Decl(primitiveUnionDetection.ts, 4, 40)) | ||
|
||
const result = getInterfaceFromString({ type: 'two' }); | ||
>result : Symbol(result, Decl(primitiveUnionDetection.ts, 6, 5)) | ||
>getInterfaceFromString : Symbol(getInterfaceFromString, Decl(primitiveUnionDetection.ts, 2, 36)) | ||
>type : Symbol(type, Decl(primitiveUnionDetection.ts, 6, 39)) | ||
|
This file contains 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,20 @@ | ||
=== tests/cases/compiler/primitiveUnionDetection.ts === | ||
// Repro from #46624 | ||
|
||
type Kind = "one" | "two" | "three"; | ||
>Kind : Kind | ||
|
||
declare function getInterfaceFromString<T extends Kind>(options?: { type?: T } & { type?: Kind }): T; | ||
>getInterfaceFromString : <T extends Kind>(options?: ({ type?: T | undefined; } & { type?: Kind | undefined; }) | undefined) => T | ||
>options : ({ type?: T | undefined; } & { type?: Kind | undefined; }) | undefined | ||
>type : T | undefined | ||
>type : Kind | undefined | ||
|
||
const result = getInterfaceFromString({ type: 'two' }); | ||
>result : "two" | ||
>getInterfaceFromString({ type: 'two' }) : "two" | ||
>getInterfaceFromString : <T extends Kind>(options?: ({ type?: T | undefined; } & { type?: Kind | undefined; }) | undefined) => T | ||
>{ type: 'two' } : { type: "two"; } | ||
>type : "two" | ||
>'two' : "two" | ||
|
This file contains 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,10 @@ | ||
// @strict: true | ||
// @declaration: true | ||
|
||
// Repro from #46624 | ||
|
||
type Kind = "one" | "two" | "three"; | ||
|
||
declare function getInterfaceFromString<T extends Kind>(options?: { type?: T } & { type?: Kind }): T; | ||
|
||
const result = getInterfaceFromString({ type: 'two' }); |