-
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
Walk up parenthesized type nodes when looking for the type alias hosting a node #32924
Conversation
@RyanCavanaugh @DanielRosenwasser do we want to consider porting this into the 3.6 release, since alias symbols are pretty important for efficient declaration emit? |
2db26ef
to
4f6473a
Compare
@typescript-bot pack this for @AnyhowStep |
Heya @weswigham, I've started to run the tarball bundle task on this PR at 4f6473a. You can monitor the build here. It should now contribute to this PR's status checks. |
@@ -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 comment
The 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. F2
gets reported as F2
but T3
prints out the tuple literal structure.
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.
Tuples are interned and don't have alias symbols, objects have alias symbols, so print as their alias if visible.
Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
Hmm... This will take me a while to test, I think. But both The repro is quite simple. Should I file an issue for this? Here's the repro with expected and actual results, export type ExtendedMapper<HandledInputT, OutputT, ArgsT extends any[]> = (
(name : string, mixed : HandledInputT, ...args : ArgsT) => OutputT
);
//type a = (name: string, mixed: any, args_0: any) => any
type a = ExtendedMapper<any, any, [any]>;
//type b = (name: string, mixed: any, ...args: any[]) => any
type b = ExtendedMapper<any, any, any[]>;
//3.5.1, [email protected]
//Expected: "y"
//Actual : "y"
//https://github.com/microsoft/TypeScript/pull/32924#issuecomment-521819476
//https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/40404/artifacts?artifactName=tgz&fileId=AD9D22CF70561BEAF5758E061B61D3FF891ADF664E37C532F5881393CE7DC83202&fileName=/typescript-3.7.0-insiders.20190815.tgz
//Expected: "y"
//Actual : "n" <-- Intentional?
type test = a extends b ? "y" : "n"
type a2 = (name: string, mixed: any, args_0: any) => any
type b2 = (name: string, mixed: any, ...args: any[]) => any
//3.5.1, [email protected]
//Expected: "y"
//Actual : "y"
//https://github.com/microsoft/TypeScript/pull/32924#issuecomment-521819476
//https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/40404/artifacts?artifactName=tgz&fileId=AD9D22CF70561BEAF5758E061B61D3FF891ADF664E37C532F5881393CE7DC83202&fileName=/typescript-3.7.0-insiders.20190815.tgz
//Expected: "y"
//Actual : "y"
type test2 = a2 extends b2 ? "y" : "n" For now, my temporary workaround is just, Extract<F, (name: string, mixed: any, ...args: any[]) => any> Because I found that It seems like assignability isn't transitive (even if we ignore |
Okay, so, I implemented the workaround making use of the fact that assignability isn't transitive, And tested what I originally wanted to test. No more max call stack size exceeded errors! If you want to test it yourself,
Thank you for fixing this so quick! |
@@ -10870,7 +10870,11 @@ namespace ts { | |||
} | |||
|
|||
function getAliasSymbolForTypeNode(node: TypeNode) { | |||
return isTypeAlias(node.parent) ? getSymbolOfNode(node.parent) : undefined; | |||
let host = node.parent; | |||
while (isParenthesizedTypeNode(host)) { |
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
Any chance of a 3.5 port? =x |
(You can make a demo reproing the difference without relying on the behavior in this PR by seeing the difference between the two types
so while this does affect how that bug manifests in your codebase, I'd like to see another issue opened for it) I would guess that would happen because the variance measures don't capture the nuance that relating spread types have (specifically the argument count effects that are independent from the type variance)... I think we'd have to propagate an |
4f6473a
to
d91c088
Compare
Fixes #32824