Skip to content

JSDoc type reference resolves incorrectly if checked before the constructor function it refers to #34685

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

Closed
sandersn opened this issue Oct 23, 2019 · 2 comments · Fixed by #34706
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@sandersn
Copy link
Member

// @filename: mod1.js
var Workspace = {}
Workspace.Project = function () { }
Workspace.Project.prototype = {
  isServiceProject() { }
}
// @filename: test.js
/** @param {Workspace.Project} p */
function demo(p) {
  p.isServiceProject()
}

Expected: no error, and p.isServiceProject(): void.

Actual: no error if you compile tsc mod1.js test.js, but an error with tsc test.js mod1.js:

Property 'isServiceProject' does not exist on type 'typeof Project'.

From chrome-devtools-frontend, failed in #34603

@sandersn sandersn added the Bug A bug in TypeScript label Oct 23, 2019
@sandersn sandersn added this to the TypeScript 3.7.2 milestone Oct 23, 2019
@sandersn sandersn self-assigned this Oct 23, 2019
@sandersn
Copy link
Member Author

Also broken by #34515, but for a different reason.

@sandersn
Copy link
Member Author

It's actually the merge + check order that's the problem. Here's a single-file repro that's careful to delay checking of Workspace.Project = function wp() { } until after its type reference:

var Workspace = {}
/** @type {Workspace.Project} */
var p;
p.isServiceProject()

Workspace.Project = function wp() { }
Workspace.Project.prototype = {
  isServiceProject() {}
}

@sandersn sandersn changed the title JSDoc type reference resolves incorrectly depending on order of compilation JSDoc type reference resolves incorrectly if checked before the constructor function it refers to Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant