Tooltip types vary depending on if type is imported or locally defined
#51,393 opened on Nov 3, 2022
Description
Bug Report
๐ Search Terms
hover different import undefined optional parameter
๐ Version & Regression Information
- This changed between versions 4.6.4 and 4.7.4
- Nightly version at time of test: 4.9.0-dev.20221025
โฏ Playground Link
๐ป Code
// @filename: input.ts
export interface MyObject {
subObject: {
MyOverloadedFn(optionalString?: string): number;
MyOverloadedFn(optionalNumber?: number, optionalString?: string): number;
};
}
type HoverExample1 = MyObject['subObject'];
/** On hover:
type HoverExample1 = {
MyOverloadedFn(optionalString?: string): number;
MyOverloadedFn(optionalNumber?: number, optionalString?: string): number;
}
//In the other file:
type HoverExample2 = {
MyOverloadedFn(optionalString?: string | undefined): number;
MyOverloadedFn(optionalNumber?: number | undefined, optionalString?: string | undefined): number;
}
*/
// @filename: file2.ts
import type { MyObject } from './input';
type HoverExample2 = MyObject['subObject'];
๐ Actual behavior
As noted in the comments, the type shown on hover is different depending on if the type is defined locally or imported from another file. Recently I came across a separate issue with an error report that reads a lot like "T is not assignable to T" with a particular focus on that | undefined bit as a possible cause. I tried copying relevant portions of code into a demonstration file to try to come up with a more minimal reproducible example of that error and wound up producing a different error instead. On trying to investigate why, I found this difference between the type in the simpler reproduction-attempt example (where the type is defined locally) and the real-world example (where it is imported) and that led me down a long rabbit-hole of confusion about this possibly being the source of the issue.
The other issue related to two subtly incompatible types relating to the same underlying library with the same name appearing to represent the same concept, buried in layers of types derived from them.
The display inconsistency bug, however, produced a more visible but less significant difference. It appears to be in TypeScript, and can be simply and easily demonstrated. Fixing it could lead others to avoid fruitless hours of their own.
This was originally observed in VSCode 1.71.0 but reproduces in the workbench.
๐ Expected behavior
The typing tooltip shown on hover is the same in both settings. With the initial issue report, I don't take a position on which one is more correct or otherwise better (I note that in 4.6.4, both versions include | undefined), but the inconsistency is problematic.