-
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.
Avoid incorrectly reusing assertion nodes from property assignments (#…
- Loading branch information
Showing
6 changed files
with
252 additions
and
3 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
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.js
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,34 @@ | ||
//// [tests/cases/compiler/declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts] //// | ||
|
||
//// [declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts] | ||
type Wrapper<T> = { | ||
_type: T; | ||
}; | ||
|
||
declare function stringWrapper(): Wrapper<string>; | ||
|
||
declare function objWrapper<T extends Record<string, Wrapper<any>>>( | ||
obj: T, | ||
): Wrapper<T>; | ||
|
||
const value = objWrapper({ | ||
prop1: stringWrapper() as Wrapper<"hello">, | ||
}); | ||
|
||
type Unwrap<T> = T extends Wrapper<any> | ||
? T["_type"] extends Record<string, Wrapper<any>> | ||
? { [Key in keyof T["_type"]]: Unwrap<T["_type"][Key]> } | ||
: T["_type"] | ||
: never; | ||
|
||
declare function unwrap<T>(wrapper: T): Unwrap<T>; | ||
|
||
export const unwrapped = unwrap(value); | ||
|
||
|
||
|
||
|
||
//// [declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.d.ts] | ||
export declare const unwrapped: { | ||
prop1: "hello"; | ||
}; |
78 changes: 78 additions & 0 deletions
78
tests/baselines/reference/declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.symbols
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,78 @@ | ||
//// [tests/cases/compiler/declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts] //// | ||
|
||
=== declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts === | ||
type Wrapper<T> = { | ||
>Wrapper : Symbol(Wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 0)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 13)) | ||
|
||
_type: T; | ||
>_type : Symbol(_type, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 19)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 13)) | ||
|
||
}; | ||
|
||
declare function stringWrapper(): Wrapper<string>; | ||
>stringWrapper : Symbol(stringWrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 2, 2)) | ||
>Wrapper : Symbol(Wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 0)) | ||
|
||
declare function objWrapper<T extends Record<string, Wrapper<any>>>( | ||
>objWrapper : Symbol(objWrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 4, 50)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 6, 28)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>Wrapper : Symbol(Wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 0)) | ||
|
||
obj: T, | ||
>obj : Symbol(obj, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 6, 68)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 6, 28)) | ||
|
||
): Wrapper<T>; | ||
>Wrapper : Symbol(Wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 0)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 6, 28)) | ||
|
||
const value = objWrapper({ | ||
>value : Symbol(value, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 10, 5)) | ||
>objWrapper : Symbol(objWrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 4, 50)) | ||
|
||
prop1: stringWrapper() as Wrapper<"hello">, | ||
>prop1 : Symbol(prop1, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 10, 26)) | ||
>stringWrapper : Symbol(stringWrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 2, 2)) | ||
>Wrapper : Symbol(Wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 0)) | ||
|
||
}); | ||
|
||
type Unwrap<T> = T extends Wrapper<any> | ||
>Unwrap : Symbol(Unwrap, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 12, 3)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 14, 12)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 14, 12)) | ||
>Wrapper : Symbol(Wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 0)) | ||
|
||
? T["_type"] extends Record<string, Wrapper<any>> | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 14, 12)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>Wrapper : Symbol(Wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 0, 0)) | ||
|
||
? { [Key in keyof T["_type"]]: Unwrap<T["_type"][Key]> } | ||
>Key : Symbol(Key, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 16, 9)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 14, 12)) | ||
>Unwrap : Symbol(Unwrap, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 12, 3)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 14, 12)) | ||
>Key : Symbol(Key, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 16, 9)) | ||
|
||
: T["_type"] | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 14, 12)) | ||
|
||
: never; | ||
|
||
declare function unwrap<T>(wrapper: T): Unwrap<T>; | ||
>unwrap : Symbol(unwrap, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 18, 10)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 20, 24)) | ||
>wrapper : Symbol(wrapper, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 20, 27)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 20, 24)) | ||
>Unwrap : Symbol(Unwrap, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 12, 3)) | ||
>T : Symbol(T, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 20, 24)) | ||
|
||
export const unwrapped = unwrap(value); | ||
>unwrapped : Symbol(unwrapped, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 22, 12)) | ||
>unwrap : Symbol(unwrap, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 18, 10)) | ||
>value : Symbol(value, Decl(declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts, 10, 5)) | ||
|
74 changes: 74 additions & 0 deletions
74
tests/baselines/reference/declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.types
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,74 @@ | ||
//// [tests/cases/compiler/declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts] //// | ||
|
||
=== declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts === | ||
type Wrapper<T> = { | ||
>Wrapper : Wrapper<T> | ||
> : ^^^^^^^^^^ | ||
|
||
_type: T; | ||
>_type : T | ||
> : ^ | ||
|
||
}; | ||
|
||
declare function stringWrapper(): Wrapper<string>; | ||
>stringWrapper : () => Wrapper<string> | ||
> : ^^^^^^ | ||
|
||
declare function objWrapper<T extends Record<string, Wrapper<any>>>( | ||
>objWrapper : <T extends Record<string, Wrapper<any>>>(obj: T) => Wrapper<T> | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ | ||
|
||
obj: T, | ||
>obj : T | ||
> : ^ | ||
|
||
): Wrapper<T>; | ||
|
||
const value = objWrapper({ | ||
>value : Wrapper<{ prop1: Wrapper<"hello">; }> | ||
> : ^^^^^^^^^^^^^^^^^ ^^^^ | ||
>objWrapper({ prop1: stringWrapper() as Wrapper<"hello">,}) : Wrapper<{ prop1: Wrapper<"hello">; }> | ||
> : ^^^^^^^^^^^^^^^^^ ^^^^ | ||
>objWrapper : <T extends Record<string, Wrapper<any>>>(obj: T) => Wrapper<T> | ||
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ | ||
>{ prop1: stringWrapper() as Wrapper<"hello">,} : { prop1: Wrapper<"hello">; } | ||
> : ^^^^^^^^^ ^^^ | ||
|
||
prop1: stringWrapper() as Wrapper<"hello">, | ||
>prop1 : Wrapper<"hello"> | ||
> : ^^^^^^^^^^^^^^^^ | ||
>stringWrapper() as Wrapper<"hello"> : Wrapper<"hello"> | ||
> : ^^^^^^^^^^^^^^^^ | ||
>stringWrapper() : Wrapper<string> | ||
> : ^^^^^^^^^^^^^^^ | ||
>stringWrapper : () => Wrapper<string> | ||
> : ^^^^^^ | ||
|
||
}); | ||
|
||
type Unwrap<T> = T extends Wrapper<any> | ||
>Unwrap : Unwrap<T> | ||
> : ^^^^^^^^^ | ||
|
||
? T["_type"] extends Record<string, Wrapper<any>> | ||
? { [Key in keyof T["_type"]]: Unwrap<T["_type"][Key]> } | ||
: T["_type"] | ||
: never; | ||
|
||
declare function unwrap<T>(wrapper: T): Unwrap<T>; | ||
>unwrap : <T>(wrapper: T) => Unwrap<T> | ||
> : ^ ^^ ^^ ^^^^^ | ||
>wrapper : T | ||
> : ^ | ||
|
||
export const unwrapped = unwrap(value); | ||
>unwrapped : { prop1: "hello"; } | ||
> : ^^^^^^^^^^^^^^^^^^^ | ||
>unwrap(value) : { prop1: "hello"; } | ||
> : ^^^^^^^^^^^^^^^^^^^ | ||
>unwrap : <T>(wrapper: T) => Unwrap<T> | ||
> : ^ ^^ ^^ ^^^^^ | ||
>value : Wrapper<{ prop1: Wrapper<"hello">; }> | ||
> : ^^^^^^^^^^^^^^^^^ ^^^^ | ||
|
27 changes: 27 additions & 0 deletions
27
tests/cases/compiler/declarationAssertionNodeNotReusedWhenTypeNotEquivalent1.ts
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,27 @@ | ||
// @strict: true | ||
// @declaration: true | ||
// @emitDeclarationOnly: true | ||
|
||
type Wrapper<T> = { | ||
_type: T; | ||
}; | ||
|
||
declare function stringWrapper(): Wrapper<string>; | ||
|
||
declare function objWrapper<T extends Record<string, Wrapper<any>>>( | ||
obj: T, | ||
): Wrapper<T>; | ||
|
||
const value = objWrapper({ | ||
prop1: stringWrapper() as Wrapper<"hello">, | ||
}); | ||
|
||
type Unwrap<T> = T extends Wrapper<any> | ||
? T["_type"] extends Record<string, Wrapper<any>> | ||
? { [Key in keyof T["_type"]]: Unwrap<T["_type"][Key]> } | ||
: T["_type"] | ||
: never; | ||
|
||
declare function unwrap<T>(wrapper: T): Unwrap<T>; | ||
|
||
export const unwrapped = unwrap(value); |
36 changes: 36 additions & 0 deletions
36
tests/cases/fourslash/quickInfoAssertionNodeNotReusedWhenTypeNotEquivalent1.ts
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,36 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// https://github.com/microsoft/TypeScript/issues/60573 | ||
|
||
// @strict: true | ||
|
||
//// type Wrapper<T> = { | ||
//// _type: T; | ||
//// }; | ||
//// | ||
//// function stringWrapper(): Wrapper<string> { | ||
//// return { _type: "" }; | ||
//// } | ||
//// | ||
//// function objWrapper<T extends Record<string, Wrapper<any>>>( | ||
//// obj: T, | ||
//// ): Wrapper<T> { | ||
//// return { _type: obj }; | ||
//// } | ||
//// | ||
//// const value = objWrapper({ | ||
//// prop1: stringWrapper() as Wrapper<"hello">, | ||
//// }); | ||
//// | ||
//// type Unwrap<T extends Wrapper<any>> = T["_type"] extends Record< | ||
//// string, | ||
//// Wrapper<any> | ||
//// > | ||
//// ? { [Key in keyof T["_type"]]: Unwrap<T["_type"][Key]> } | ||
//// : T["_type"]; | ||
//// | ||
//// type Test/*1*/ = Unwrap<typeof value>; | ||
|
||
verify.quickInfoAt("1", `type Test = { | ||
prop1: "hello"; | ||
}`) |