Skip to content
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

(JSDoc, JavaScript) Imported class types by require() are unresolved #59964

Open
myocytebd opened this issue Sep 13, 2024 · 1 comment
Open
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@myocytebd
Copy link

myocytebd commented Sep 13, 2024

Type: Bug

Does this issue occur when all extensions are disabled?: Yes

  • VS Code version: Code 1.93.1 (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
  • OS version: Linux x64 6.5.0-44-generic

Steps to Reproduce:

With source code below (a.js & b.js), there are two issues present in b.js, A and B.

  1. Issue.B is triggered without modification.
    TS server reports a.Foo as alias of class Foo, but Foo as unresolved.
  2. Issue.A is triggered if any of value/obj field or prop getter line is enabled in a.js exports.
    TS server reports a.Foo as unresolved.
    The only pattern to make TS server happy is localObj line.

IMO diagnostics information should be presented other than the casual /* unresolved */ any message.

// a.js
class Foo {
    constructor() {
        this.fprop = 123;
    }
}
const localObj = { prop: 456 };

exports = module.exports = {
    Foo,
    // value: 123,
    // obj: { prop: 456 },
    // get prop() { return 789 },
    // localObj,
};
// b.js
const a = require('./a');
const { Foo, } = a;

class Bar {
    /** @param {a.Foo} foo */
    constructor(foo) {
        this.bprop = foo.fprop;
    }
}

// Issue.A: a.Foo unresolved, .fprop is any
/** @param {a.Foo} foo */
function bar1(foo) {
    foo.fprop;
}

// Issue.B: Foo unresolved, .fprop is any
/** @param {Foo} foo */
function bar2(foo) {
    foo.fprop;
}

VS Code version: Code 1.93.1 (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
OS version: Linux x64 6.5.0-44-generic
Modes:

A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonnoceb:30805159
asynctok:30898717
pythonregdiag2:30936856
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
9c06g630:31013171
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
impr_priority:31102340
refactort:31101459
ccplti:31098112

@mjbvz mjbvz transferred this issue from microsoft/vscode Sep 13, 2024
@mjbvz mjbvz removed their assignment Sep 13, 2024
@ExE-Boss
Copy link
Contributor

// @module: CommonJS
// @allowJs
// @checkJs

// @filename: a.js
class Foo {
	constructor() {
		this.fprop = 123;
	}
}
const localObj = { prop: 456 };

exports = module.exports = {
	Foo,
	// value: 123,
	// obj: { prop: 456 },
	// get prop() { return 789 },
	// localObj,
};

// @filename: b.js
const a = require("./a.js");
const { Foo } = a;

class Bar {
	/** @param {a.Foo} foo */
	constructor(foo) {
	//            ^?
		this.bprop = foo.fprop;
	}
}

// Issue.A: a.Foo unresolved, .fprop is any
/** @param {a.Foo} foo */
function bar1(foo) {
//              ^?
	foo.fprop;
}

// Issue.B: Foo unresolved, .fprop is any
/** @param {Foo} foo */
function bar2(foo) {
//              ^?
	foo.fprop;
}

Workbench Repro

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Sep 20, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.0 milestone Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

5 participants