-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix name resolution in typedef and allow defaults for template tags #45483
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3d9187f
Fix name resolution in typedef and allow defaults for template tags
rbuckton 8460ea4
Inline parseBracketNameInTemplateTag
rbuckton 9e24ccf
Merge branch 'main' into jsDocTemplateTagDefault
rbuckton 9131c0c
Update baselines
rbuckton 490e681
Add js declaration emit tests
rbuckton 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
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
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
90 changes: 90 additions & 0 deletions
90
tests/baselines/reference/jsdocTemplateTagDefault.errors.txt
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,90 @@ | ||
tests/cases/conformance/jsdoc/file.js(9,20): error TS2322: Type 'number' is not assignable to type 'string'. | ||
tests/cases/conformance/jsdoc/file.js(22,34): error TS1005: '=' expected. | ||
tests/cases/conformance/jsdoc/file.js(27,35): error TS1110: Type expected. | ||
tests/cases/conformance/jsdoc/file.js(33,14): error TS2706: Required type parameters may not follow optional type parameters. | ||
tests/cases/conformance/jsdoc/file.js(38,17): error TS2744: Type parameter defaults can only reference previously declared type parameters. | ||
tests/cases/conformance/jsdoc/file.js(53,14): error TS2706: Required type parameters may not follow optional type parameters. | ||
tests/cases/conformance/jsdoc/file.js(60,17): error TS2744: Type parameter defaults can only reference previously declared type parameters. | ||
|
||
|
||
==== tests/cases/conformance/jsdoc/file.js (7 errors) ==== | ||
/** | ||
* @template {string | number} [T=string] - ok: defaults are permitted | ||
* @typedef {[T]} A | ||
*/ | ||
|
||
/** @type {A} */ // ok, default for `T` in `A` is `string` | ||
const aDefault1 = [""]; | ||
/** @type {A} */ // error: `number` is not assignable to string` | ||
const aDefault2 = [0]; | ||
~ | ||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | ||
/** @type {A<string>} */ // ok, `T` is provided for `A` | ||
const aString = [""]; | ||
/** @type {A<number>} */ // ok, `T` is provided for `A` | ||
const aNumber = [0]; | ||
|
||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @typedef {[T, U]} B | ||
*/ | ||
|
||
/** | ||
* @template {string | number} [T] - error: default requires an `=type` | ||
~ | ||
!!! error TS1005: '=' expected. | ||
* @typedef {[T]} C | ||
*/ | ||
|
||
/** | ||
* @template {string | number} [T=] - error: default requires a `type` | ||
~ | ||
!!! error TS1110: Type expected. | ||
* @typedef {[T]} D | ||
*/ | ||
|
||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
~ | ||
!!! error TS2706: Required type parameters may not follow optional type parameters. | ||
* @typedef {[T, U]} E | ||
*/ | ||
|
||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
~ | ||
!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @typedef {[T, U]} G | ||
*/ | ||
|
||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f1(a, b) {} | ||
|
||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
~ | ||
!!! error TS2706: Required type parameters may not follow optional type parameters. | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f2(a, b) {} | ||
|
||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
~ | ||
!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f3(a, b) {} | ||
|
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,186 @@ | ||
//// [file.js] | ||
/** | ||
* @template {string | number} [T=string] - ok: defaults are permitted | ||
* @typedef {[T]} A | ||
*/ | ||
|
||
/** @type {A} */ // ok, default for `T` in `A` is `string` | ||
const aDefault1 = [""]; | ||
/** @type {A} */ // error: `number` is not assignable to string` | ||
const aDefault2 = [0]; | ||
/** @type {A<string>} */ // ok, `T` is provided for `A` | ||
const aString = [""]; | ||
/** @type {A<number>} */ // ok, `T` is provided for `A` | ||
const aNumber = [0]; | ||
|
||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @typedef {[T, U]} B | ||
*/ | ||
|
||
/** | ||
* @template {string | number} [T] - error: default requires an `=type` | ||
* @typedef {[T]} C | ||
*/ | ||
|
||
/** | ||
* @template {string | number} [T=] - error: default requires a `type` | ||
* @typedef {[T]} D | ||
*/ | ||
|
||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @typedef {[T, U]} E | ||
*/ | ||
|
||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @typedef {[T, U]} G | ||
*/ | ||
|
||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f1(a, b) {} | ||
|
||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f2(a, b) {} | ||
|
||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f3(a, b) {} | ||
|
||
|
||
//// [file.js] | ||
/** | ||
* @template {string | number} [T=string] - ok: defaults are permitted | ||
* @typedef {[T]} A | ||
*/ | ||
/** @type {A} */ // ok, default for `T` in `A` is `string` | ||
var aDefault1 = [""]; | ||
/** @type {A} */ // error: `number` is not assignable to string` | ||
var aDefault2 = [0]; | ||
/** @type {A<string>} */ // ok, `T` is provided for `A` | ||
var aString = [""]; | ||
/** @type {A<number>} */ // ok, `T` is provided for `A` | ||
var aNumber = [0]; | ||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @typedef {[T, U]} B | ||
*/ | ||
/** | ||
* @template {string | number} [T] - error: default requires an `=type` | ||
* @typedef {[T]} C | ||
*/ | ||
/** | ||
* @template {string | number} [T=] - error: default requires a `type` | ||
* @typedef {[T]} D | ||
*/ | ||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @typedef {[T, U]} E | ||
*/ | ||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @typedef {[T, U]} G | ||
*/ | ||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f1(a, b) { } | ||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f2(a, b) { } | ||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
function f3(a, b) { } | ||
|
||
|
||
//// [file.d.ts] | ||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @typedef {[T, U]} B | ||
*/ | ||
/** | ||
* @template {string | number} [T] - error: default requires an `=type` | ||
* @typedef {[T]} C | ||
*/ | ||
/** | ||
* @template {string | number} [T=] - error: default requires a `type` | ||
* @typedef {[T]} D | ||
*/ | ||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @typedef {[T, U]} E | ||
*/ | ||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @typedef {[T, U]} G | ||
*/ | ||
/** | ||
* @template T | ||
* @template [U=T] - ok: default can reference earlier type parameter | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
declare function f1<T, U = T>(a: T, b: U): void; | ||
/** | ||
* @template {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
declare function f2<T extends string | number = string, U>(a: T, b: U): void; | ||
/** | ||
* @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. | ||
* @template [U=T] | ||
* @param {T} a | ||
* @param {U} b | ||
*/ | ||
declare function f3<T = U, U = T>(a: T, b: U): void; | ||
/** | ||
* @template {string | number} [T=string] - ok: defaults are permitted | ||
* @typedef {[T]} A | ||
*/ | ||
/** @type {A} */ declare const aDefault1: A<string>; | ||
/** @type {A} */ declare const aDefault2: A<string>; | ||
/** @type {A<string>} */ declare const aString: A<string>; | ||
/** @type {A<number>} */ declare const aNumber: A<number>; | ||
type B<T, U = T> = [T, U]; | ||
type C<T extends string | number = any> = [T]; | ||
type D<T extends string | number = any> = [T]; | ||
type E<T extends string | number = string, U> = [T, U]; | ||
type G<T = U, U = T> = [T, U]; | ||
type A<T extends string | number = string> = [T]; |
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.