Skip to content

Fix import type resolution in jsdoc, mark 2 #35057

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

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10852,7 +10852,8 @@ namespace ts {
}
isRequireAlias = isCallExpression(expr) && isRequireCall(expr, /*requireStringLiteralLikeArgument*/ true) && !!valueType.symbol;
}
if (isRequireAlias || node.kind === SyntaxKind.ImportType) {
const isImportTypeWithQualifier = node.kind === SyntaxKind.ImportType && (node as ImportTypeNode).qualifier;
if (isRequireAlias || isImportTypeWithQualifier) {
typeType = getTypeReferenceType(node, valueType.symbol);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== tests/cases/conformance/jsdoc/ex.d.ts ===
declare var config: {
>config : Symbol(config, Decl(ex.d.ts, 0, 11))

fix: boolean
>fix : Symbol(fix, Decl(ex.d.ts, 0, 21))
}
export = config;
>config : Symbol(config, Decl(ex.d.ts, 0, 11))

=== tests/cases/conformance/jsdoc/test.js ===
/** @param {import('./ex')} a */
function demo(a) {
>demo : Symbol(demo, Decl(test.js, 0, 0))
>a : Symbol(a, Decl(test.js, 1, 14))

a.fix
>a.fix : Symbol(fix, Decl(ex.d.ts, 0, 21))
>a : Symbol(a, Decl(test.js, 1, 14))
>fix : Symbol(fix, Decl(ex.d.ts, 0, 21))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== tests/cases/conformance/jsdoc/ex.d.ts ===
declare var config: {
>config : { fix: boolean; }

fix: boolean
>fix : boolean
}
export = config;
>config : { fix: boolean; }

=== tests/cases/conformance/jsdoc/test.js ===
/** @param {import('./ex')} a */
function demo(a) {
>demo : (a: { fix: boolean; }) => void
>a : { fix: boolean; }

a.fix
>a.fix : boolean
>a : { fix: boolean; }
>fix : boolean
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/conformance/jsdoc/ex.d.ts ===
export var config: {}
>config : Symbol(config, Decl(ex.d.ts, 0, 10))

=== tests/cases/conformance/jsdoc/test.js ===
/** @param {import('./ex')} a */
function demo(a) {
>demo : Symbol(demo, Decl(test.js, 0, 0))
>a : Symbol(a, Decl(test.js, 1, 14))

a.config
>a.config : Symbol(config, Decl(ex.d.ts, 0, 10))
>a : Symbol(a, Decl(test.js, 1, 14))
>config : Symbol(config, Decl(ex.d.ts, 0, 10))
}

16 changes: 16 additions & 0 deletions tests/baselines/reference/jsdocImportTypeReferenceToESModule.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
=== tests/cases/conformance/jsdoc/ex.d.ts ===
export var config: {}
>config : {}

=== tests/cases/conformance/jsdoc/test.js ===
/** @param {import('./ex')} a */
function demo(a) {
>demo : (a: typeof import("tests/cases/conformance/jsdoc/ex")) => void
>a : typeof import("tests/cases/conformance/jsdoc/ex")

a.config
>a.config : {}
>a : typeof import("tests/cases/conformance/jsdoc/ex")
>config : {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: ex.d.ts
declare var config: {
fix: boolean
}
export = config;

// @Filename: test.js
/** @param {import('./ex')} a */
function demo(a) {
a.fix
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: ex.d.ts
export var config: {}

// @Filename: test.js
/** @param {import('./ex')} a */
function demo(a) {
a.config
}