-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Walk up parenthesized type nodes when looking for the type alias hosting a node #32924
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ type F1 = ([a, b, c]) => void; | |
>c : any | ||
|
||
type T2 = ({ a }); | ||
>T2 : { a: any; } | ||
>T2 : T2 | ||
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 can’t tell whether this makes sense because I can’t immediately deduce the rule for type readouts by reading the pre-existing examples below. 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. Tuples are interned and don't have alias symbols, objects have alias symbols, so print as their alias if visible. |
||
>a : any | ||
|
||
type F2 = ({ a }) => void; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//// [parenthesisDoesNotBlockAliasSymbolCreation.ts] | ||
export type InvalidKeys<K extends string|number|symbol> = { [P in K]? : never }; | ||
export type InvalidKeys2<K extends string|number|symbol> = ( | ||
{ [P in K]? : never } | ||
); | ||
|
||
export type A<T> = ( | ||
T & InvalidKeys<"a"> | ||
); | ||
export type A2<T> = ( | ||
T & InvalidKeys2<"a"> | ||
); | ||
|
||
export const a = null as A<{ x : number }>; | ||
export const a2 = null as A2<{ x : number }>; | ||
export const a3 = null as { x : number } & InvalidKeys<"a">; | ||
export const a4 = null as { x : number } & InvalidKeys2<"a">; | ||
|
||
|
||
//// [parenthesisDoesNotBlockAliasSymbolCreation.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.a = null; | ||
exports.a2 = null; | ||
exports.a3 = null; | ||
exports.a4 = null; | ||
|
||
|
||
//// [parenthesisDoesNotBlockAliasSymbolCreation.d.ts] | ||
export declare type InvalidKeys<K extends string | number | symbol> = { | ||
[P in K]?: never; | ||
}; | ||
export declare type InvalidKeys2<K extends string | number | symbol> = ({ | ||
[P in K]?: never; | ||
}); | ||
export declare type A<T> = (T & InvalidKeys<"a">); | ||
export declare type A2<T> = (T & InvalidKeys2<"a">); | ||
export declare const a: A<{ | ||
x: number; | ||
}>; | ||
export declare const a2: A2<{ | ||
x: number; | ||
}>; | ||
export declare const a3: { | ||
x: number; | ||
} & InvalidKeys<"a">; | ||
export declare const a4: { | ||
x: number; | ||
} & InvalidKeys2<"a">; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
=== tests/cases/compiler/parenthesisDoesNotBlockAliasSymbolCreation.ts === | ||
export type InvalidKeys<K extends string|number|symbol> = { [P in K]? : never }; | ||
>InvalidKeys : Symbol(InvalidKeys, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 0)) | ||
>K : Symbol(K, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 24)) | ||
>P : Symbol(P, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 61)) | ||
>K : Symbol(K, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 24)) | ||
|
||
export type InvalidKeys2<K extends string|number|symbol> = ( | ||
>InvalidKeys2 : Symbol(InvalidKeys2, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 80)) | ||
>K : Symbol(K, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 1, 25)) | ||
|
||
{ [P in K]? : never } | ||
>P : Symbol(P, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 2, 7)) | ||
>K : Symbol(K, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 1, 25)) | ||
|
||
); | ||
|
||
export type A<T> = ( | ||
>A : Symbol(A, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 3, 2)) | ||
>T : Symbol(T, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 5, 14)) | ||
|
||
T & InvalidKeys<"a"> | ||
>T : Symbol(T, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 5, 14)) | ||
>InvalidKeys : Symbol(InvalidKeys, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 0)) | ||
|
||
); | ||
export type A2<T> = ( | ||
>A2 : Symbol(A2, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 7, 2)) | ||
>T : Symbol(T, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 8, 15)) | ||
|
||
T & InvalidKeys2<"a"> | ||
>T : Symbol(T, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 8, 15)) | ||
>InvalidKeys2 : Symbol(InvalidKeys2, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 80)) | ||
|
||
); | ||
|
||
export const a = null as A<{ x : number }>; | ||
>a : Symbol(a, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 12, 12)) | ||
>A : Symbol(A, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 3, 2)) | ||
>x : Symbol(x, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 12, 28)) | ||
|
||
export const a2 = null as A2<{ x : number }>; | ||
>a2 : Symbol(a2, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 13, 12)) | ||
>A2 : Symbol(A2, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 7, 2)) | ||
>x : Symbol(x, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 13, 30)) | ||
|
||
export const a3 = null as { x : number } & InvalidKeys<"a">; | ||
>a3 : Symbol(a3, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 14, 12)) | ||
>x : Symbol(x, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 14, 27)) | ||
>InvalidKeys : Symbol(InvalidKeys, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 0)) | ||
|
||
export const a4 = null as { x : number } & InvalidKeys2<"a">; | ||
>a4 : Symbol(a4, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 15, 12)) | ||
>x : Symbol(x, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 15, 27)) | ||
>InvalidKeys2 : Symbol(InvalidKeys2, Decl(parenthesisDoesNotBlockAliasSymbolCreation.ts, 0, 80)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
=== tests/cases/compiler/parenthesisDoesNotBlockAliasSymbolCreation.ts === | ||
export type InvalidKeys<K extends string|number|symbol> = { [P in K]? : never }; | ||
>InvalidKeys : InvalidKeys<K> | ||
|
||
export type InvalidKeys2<K extends string|number|symbol> = ( | ||
>InvalidKeys2 : InvalidKeys2<K> | ||
|
||
{ [P in K]? : never } | ||
); | ||
|
||
export type A<T> = ( | ||
>A : A<T> | ||
|
||
T & InvalidKeys<"a"> | ||
); | ||
export type A2<T> = ( | ||
>A2 : A2<T> | ||
|
||
T & InvalidKeys2<"a"> | ||
); | ||
|
||
export const a = null as A<{ x : number }>; | ||
>a : A<{ x: number; }> | ||
>null as A<{ x : number }> : A<{ x: number; }> | ||
>null : null | ||
>x : number | ||
|
||
export const a2 = null as A2<{ x : number }>; | ||
>a2 : A2<{ x: number; }> | ||
>null as A2<{ x : number }> : A2<{ x: number; }> | ||
>null : null | ||
>x : number | ||
|
||
export const a3 = null as { x : number } & InvalidKeys<"a">; | ||
>a3 : { x: number; } & InvalidKeys<"a"> | ||
>null as { x : number } & InvalidKeys<"a"> : { x: number; } & InvalidKeys<"a"> | ||
>null : null | ||
>x : number | ||
|
||
export const a4 = null as { x : number } & InvalidKeys2<"a">; | ||
>a4 : { x: number; } & InvalidKeys2<"a"> | ||
>null as { x : number } & InvalidKeys2<"a"> : { x: number; } & InvalidKeys2<"a"> | ||
>null : null | ||
>x : number | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @declaration: true | ||
|
||
export type InvalidKeys<K extends string|number|symbol> = { [P in K]? : never }; | ||
export type InvalidKeys2<K extends string|number|symbol> = ( | ||
{ [P in K]? : never } | ||
); | ||
|
||
export type A<T> = ( | ||
T & InvalidKeys<"a"> | ||
); | ||
export type A2<T> = ( | ||
T & InvalidKeys2<"a"> | ||
); | ||
|
||
export const a = null as A<{ x : number }>; | ||
export const a2 = null as A2<{ x : number }>; | ||
export const a3 = null as { x : number } & InvalidKeys<"a">; | ||
export const a4 = null as { x : number } & InvalidKeys2<"a">; |
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.
<3