-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix(60908): Unexpected "'Type' is declared but its value is never read." error with jsdoc @import syntax #60921
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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7d1ed12
fix(60908): avoid binding jsdocimport children to the jsdoc host cont…
a-tarasyuk 49cdbda
add additional tests
a-tarasyuk 7c18a9c
prevent early binding of importClause in jsdoc imports
a-tarasyuk 9f439bb
Merge branch 'main' of https://github.com/microsoft/TypeScript into f…
a-tarasyuk 58f9d2f
add tests
a-tarasyuk 9649ed0
experiment: treat import tag as a container
a-tarasyuk d7a3e0c
add clarifying comment
a-tarasyuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//// [tests/cases/conformance/jsdoc/importTag23.ts] //// | ||
|
||
=== types.d.ts === | ||
export type T = { | ||
>T : Symbol(T, Decl(types.d.ts, 0, 0)) | ||
|
||
a: number; | ||
>a : Symbol(a, Decl(types.d.ts, 0, 17)) | ||
|
||
}; | ||
|
||
=== foo.js === | ||
/** @import { T } from "./types.d.ts" */ | ||
|
||
export default async function f() { | ||
>f : Symbol(f, Decl(foo.js, 0, 0)) | ||
|
||
/** @type {T[]} */ | ||
const types = []; | ||
>types : Symbol(types, Decl(foo.js, 4, 6)) | ||
|
||
return types; | ||
>types : Symbol(types, Decl(foo.js, 4, 6)) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//// [tests/cases/conformance/jsdoc/importTag23.ts] //// | ||
|
||
=== types.d.ts === | ||
export type T = { | ||
>T : T | ||
> : ^ | ||
|
||
a: number; | ||
>a : number | ||
> : ^^^^^^ | ||
|
||
}; | ||
|
||
=== foo.js === | ||
/** @import { T } from "./types.d.ts" */ | ||
|
||
export default async function f() { | ||
>f : () => Promise<T[]> | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
|
||
/** @type {T[]} */ | ||
const types = []; | ||
>types : T[] | ||
> : ^^^ | ||
>[] : undefined[] | ||
> : ^^^^^^^^^^^ | ||
|
||
return types; | ||
>types : T[] | ||
> : ^^^ | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
a.js(3,10): error TS6133: 'f1' is declared but its value is never read. | ||
a.js(11,10): error TS6133: 'f3' is declared but its value is never read. | ||
a.js(19,10): error TS6133: 'f4' is declared but its value is never read. | ||
a.js(19,17): error TS2322: Type 'number' is not assignable to type 'string'. | ||
|
||
|
||
==== types.d.ts (0 errors) ==== | ||
export type Foo = string; | ||
|
||
==== a.js (4 errors) ==== | ||
/** @import { Foo } from './types.d.ts') */ | ||
|
||
function f1() { return undefined; } | ||
~~ | ||
!!! error TS6133: 'f1' is declared but its value is never read. | ||
|
||
export function f2() { | ||
/** @type {Set<Foo>} */ | ||
const foo = new Set([ 'a', 'b' ]); | ||
return foo; | ||
} | ||
|
||
function f3() { return undefined; } | ||
~~ | ||
!!! error TS6133: 'f3' is declared but its value is never read. | ||
|
||
/** @type {Set<Foo>} */ | ||
export const foo = new Set([ 'a', 'b' ]); | ||
|
||
/** | ||
* @returns {Foo} | ||
*/ | ||
function f4() { return 1; } | ||
~~ | ||
!!! error TS6133: 'f4' is declared but its value is never read. | ||
~~~~~~ | ||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//// [tests/cases/conformance/jsdoc/importTag24.ts] //// | ||
|
||
=== types.d.ts === | ||
export type Foo = string; | ||
>Foo : Symbol(Foo, Decl(types.d.ts, 0, 0)) | ||
|
||
=== a.js === | ||
/** @import { Foo } from './types.d.ts') */ | ||
|
||
function f1() { return undefined; } | ||
>f1 : Symbol(f1, Decl(a.js, 0, 0)) | ||
>undefined : Symbol(undefined) | ||
|
||
export function f2() { | ||
>f2 : Symbol(f2, Decl(a.js, 2, 35)) | ||
|
||
/** @type {Set<Foo>} */ | ||
const foo = new Set([ 'a', 'b' ]); | ||
>foo : Symbol(foo, Decl(a.js, 6, 9)) | ||
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) | ||
|
||
return foo; | ||
>foo : Symbol(foo, Decl(a.js, 6, 9)) | ||
} | ||
|
||
function f3() { return undefined; } | ||
>f3 : Symbol(f3, Decl(a.js, 8, 1)) | ||
>undefined : Symbol(undefined) | ||
|
||
/** @type {Set<Foo>} */ | ||
export const foo = new Set([ 'a', 'b' ]); | ||
>foo : Symbol(foo, Decl(a.js, 13, 12)) | ||
>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --)) | ||
|
||
/** | ||
* @returns {Foo} | ||
*/ | ||
function f4() { return 1; } | ||
>f4 : Symbol(f4, Decl(a.js, 13, 41)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//// [tests/cases/conformance/jsdoc/importTag24.ts] //// | ||
|
||
=== Performance Stats === | ||
Type Count: 1,000 | ||
Instantiation count: 2,500 | ||
|
||
=== types.d.ts === | ||
export type Foo = string; | ||
>Foo : string | ||
> : ^^^^^^ | ||
|
||
=== a.js === | ||
/** @import { Foo } from './types.d.ts') */ | ||
|
||
function f1() { return undefined; } | ||
>f1 : () => any | ||
> : ^^^^^^^^^ | ||
>undefined : undefined | ||
> : ^^^^^^^^^ | ||
|
||
export function f2() { | ||
>f2 : () => Set<string> | ||
> : ^^^^^^^^^^^^^^^^^ | ||
|
||
/** @type {Set<Foo>} */ | ||
const foo = new Set([ 'a', 'b' ]); | ||
>foo : Set<string> | ||
> : ^^^^^^^^^^^ | ||
>new Set([ 'a', 'b' ]) : Set<string> | ||
> : ^^^^^^^^^^^ | ||
>Set : SetConstructor | ||
> : ^^^^^^^^^^^^^^ | ||
>[ 'a', 'b' ] : string[] | ||
> : ^^^^^^^^ | ||
>'a' : "a" | ||
> : ^^^ | ||
>'b' : "b" | ||
> : ^^^ | ||
|
||
return foo; | ||
>foo : Set<string> | ||
> : ^^^^^^^^^^^ | ||
} | ||
|
||
function f3() { return undefined; } | ||
>f3 : () => any | ||
> : ^^^^^^^^^ | ||
>undefined : undefined | ||
> : ^^^^^^^^^ | ||
|
||
/** @type {Set<Foo>} */ | ||
export const foo = new Set([ 'a', 'b' ]); | ||
>foo : Set<string> | ||
> : ^^^^^^^^^^^ | ||
>new Set([ 'a', 'b' ]) : Set<string> | ||
> : ^^^^^^^^^^^ | ||
>Set : SetConstructor | ||
> : ^^^^^^^^^^^^^^ | ||
>[ 'a', 'b' ] : string[] | ||
> : ^^^^^^^^ | ||
>'a' : "a" | ||
> : ^^^ | ||
>'b' : "b" | ||
> : ^^^ | ||
|
||
/** | ||
* @returns {Foo} | ||
*/ | ||
function f4() { return 1; } | ||
>f4 : () => Foo | ||
> : ^^^^^^^^^ | ||
>1 : 1 | ||
> : ^ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @noUnusedLocals: true | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
|
||
// @filename: types.d.ts | ||
export type T = { | ||
a: number; | ||
}; | ||
|
||
// @filename: foo.js | ||
/** @import { T } from "./types.d.ts" */ | ||
|
||
export default async function f() { | ||
/** @type {T[]} */ | ||
const types = []; | ||
return types; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// @checkJs: true | ||
// @allowJs: true | ||
// @noEmit: true | ||
// @lib: esnext | ||
// @moduleResolution: bundler | ||
// @module: preserve | ||
// @noUnusedLocals: true | ||
// @noUnusedParameters: true | ||
// @allowImportingTsExtensions: true | ||
|
||
// @filename: types.d.ts | ||
export type Foo = string; | ||
|
||
// @filename: a.js | ||
/** @import { Foo } from './types.d.ts') */ | ||
|
||
function f1() { return undefined; } | ||
|
||
export function f2() { | ||
/** @type {Set<Foo>} */ | ||
const foo = new Set([ 'a', 'b' ]); | ||
return foo; | ||
} | ||
|
||
function f3() { return undefined; } | ||
|
||
/** @type {Set<Foo>} */ | ||
export const foo = new Set([ 'a', 'b' ]); | ||
|
||
/** | ||
* @returns {Foo} | ||
*/ | ||
function f4() { return 1; } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.