Getting type information for a node causes other nodes to return any for their type
See original GitHub issueBug Report
๐ Search Terms
Compiler API, unexpected any
๐ Version & Regression Information
- This changed between versions 4.5.x and 4.6.x
This does not repro on 4.5.5, but repros against v4.6.2
โฏ Playground Link
Playground link with relevant code
๐ป Code
export function getFutureVersion(baseVersion?: string): number[] {
const toRelease: number[] = [];
const baseRelease: number[] = [];
return baseRelease.map((_, index) => {
const toPart = toRelease[index] ?? 0;
if (index < 1) {
return toPart;
}
if (index === 1) {
toPart;
// ^? any
toPart.lol; // Property 'lol' does not exist on type 'number'.(2339)
// ^? any
return toPart + (baseVersion === undefined ? 0 : 1);
}
return 0;
});
}
๐ Actual behavior
You can see that in this repro intellisense reports the type of toPart
as any
even though TS also knows that it must be a number.
If I attempt to get the type of toPart
:
window.sandbox.createTSProgram().then(program => {
program.emit()
const ast = program.getSourceFile('/input.tsx');
console.log(
program.getTypeChecker().getTypeAtLocation(
ast.statements[0].body.statements[2].expression.arguments[0].body.statements[2].thenStatement.statements[0].expression,
),
);
});
// -> {checker: {โฆ}, flags: 1, id: 1, intrinsicName: 'any', objectFlags: 0}
Hazarding a guess intellisense and the ^?
playground token both just use checker.getTypeAtLocation(node)
to get the type (and checker.typeToString
to print it).
If you switch the TS version to 4.5 then youโll see that the type is correctly printed as number
and the above snippet logs:
{checker: {โฆ}, flags: 8, id: 14, intrinsicName: 'number', objectFlags: 0}
๐ Expected behavior
The 4.5 behaviour is correct - getTypeAtLocation
should return a number
type.
Related
https://github.com/typescript-eslint/typescript-eslint/issues/4689
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Node properties: type, tag and contents
The tagName property exists only for Element nodes. The nodeName is defined for any Node : for elements it means the same as...
Read more >Node (JavaFX 8) - Oracle Help Center
Specifies whether this Node and any subnodes should be rendered as part of the scene graph. Field Summary. Fields. Modifier and Type, Field...
Read more >MATCH - Cypher Manual - Neo4j
Get all nodes โโ By just specifying a pattern with a single node and no labels, all nodes in the graph will be...
Read more >Writing Functions - Node-RED
In general, function nodes should return the message object they were passed ... This makes it easy to write a function that sends...
Read more >NodeList - Web APIs | MDN
Chrome Edge Fir...
NodeList Full support. Chrome1. Toggle history Full support. Edge12. Toggle history Fu...
@@iterator Full support. Chrome51. Toggle history Full support. Edge79. Toggle...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@RyanCavanaugh this repro just depends on TS using
4.7.0-dev.20220418
: https://github.com/bradzacher/TS-48313-REPRO/tree/mainThis issue appears to be fixed in the 4.7 nightly: https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&useUnknownInCatchVariables=true&noFallthroughCasesInSwitch=true&noImplicitOverride=true&ts=4.7.0-dev.20220331#code/KYDwDg9gTgLgBAMwK4DsDGMCWEVwObAwBiSMSUwAasFAM7YoAUARgIa1U304D8AXHFowomFHgCUAlEgC2zGgG0AunADeAKDhw0OIXBgQASsAA2wdsCmz5UZXAC8cZQG5N23fDYdjZi1bmKKo4ubhRkULhewD7mHAB0MqxgjIwA+gA0cKIAJqDiDgB8am5aOih6BgAKrLAO+kamscAKOaAqPDxwAAyuWlqYCHCMrSBwADxwAIz5Gn19YeS4VTUwvX0AviVZg8MouaP2h1MzW1rLsGtzAPRXWgB6PKf11bBxJhAmznA3cJVQEGAaDAAJ5wADk7xMYLg2QgwFocBQEHgoEwehw+mBgPB0gCUDBcUYACYAMwkgCc4iePzgDyeCwizxWcAA1EMotQ6AwHEdULkEKJgNk4J0unABNMvltNnMGbgem51uJXOsgA @bradzacher Do you think you can try and see if any of the original issues in https://github.com/typescript-eslint/typescript-eslint/issues/4689 are also fixed in the nightly version?