-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix name resolution in typedef and allow defaults for template tags
- Loading branch information
Showing
12 changed files
with
462 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
99 changes: 99 additions & 0 deletions
99
tests/baselines/reference/jsdocTemplateTagDefault.errors.txt
This file contains 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,99 @@ | ||
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(39,14): error TS2706: Required type parameters may not follow optional type parameters. | ||
tests/cases/conformance/jsdoc/file.js(44,17): error TS2744: Type parameter defaults can only reference previously declared type parameters. | ||
tests/cases/conformance/jsdoc/file.js(59,14): error TS2706: Required type parameters may not follow optional type parameters. | ||
tests/cases/conformance/jsdoc/file.js(66,17): error TS2744: Type parameter defaults can only reference previously declared type parameters. | ||
|
||
|
||
==== tests/cases/conformance/jsdoc/file.js (8 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 {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]} F | ||
*/ | ||
|
||
/** | ||
* @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 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,89 @@ | ||
=== tests/cases/conformance/jsdoc/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 = [""]; | ||
>aDefault1 : Symbol(aDefault1, Decl(file.js, 6, 5)) | ||
|
||
/** @type {A} */ // error: `number` is not assignable to string` | ||
const aDefault2 = [0]; | ||
>aDefault2 : Symbol(aDefault2, Decl(file.js, 8, 5)) | ||
|
||
/** @type {A<string>} */ // ok, `T` is provided for `A` | ||
const aString = [""]; | ||
>aString : Symbol(aString, Decl(file.js, 10, 5)) | ||
|
||
/** @type {A<number>} */ // ok, `T` is provided for `A` | ||
const aNumber = [0]; | ||
>aNumber : Symbol(aNumber, Decl(file.js, 12, 5)) | ||
|
||
/** | ||
* @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 {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @typedef {[T, U]} F | ||
*/ | ||
|
||
/** | ||
* @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) {} | ||
>f1 : Symbol(f1, Decl(file.js, 12, 20)) | ||
>a : Symbol(a, Decl(file.js, 54, 12)) | ||
>b : Symbol(b, Decl(file.js, 54, 14)) | ||
|
||
/** | ||
* @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) {} | ||
>f2 : Symbol(f2, Decl(file.js, 54, 20)) | ||
>a : Symbol(a, Decl(file.js, 62, 12)) | ||
>b : Symbol(b, Decl(file.js, 62, 14)) | ||
|
||
/** | ||
* @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) {} | ||
>f3 : Symbol(f3, Decl(file.js, 62, 20)) | ||
>a : Symbol(a, Decl(file.js, 70, 12)) | ||
>b : Symbol(b, Decl(file.js, 70, 14)) | ||
|
This file contains 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,97 @@ | ||
=== tests/cases/conformance/jsdoc/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 = [""]; | ||
>aDefault1 : A<string> | ||
>[""] : [string] | ||
>"" : "" | ||
|
||
/** @type {A} */ // error: `number` is not assignable to string` | ||
const aDefault2 = [0]; | ||
>aDefault2 : A<string> | ||
>[0] : [number] | ||
>0 : 0 | ||
|
||
/** @type {A<string>} */ // ok, `T` is provided for `A` | ||
const aString = [""]; | ||
>aString : A<string> | ||
>[""] : [string] | ||
>"" : "" | ||
|
||
/** @type {A<number>} */ // ok, `T` is provided for `A` | ||
const aNumber = [0]; | ||
>aNumber : A<number> | ||
>[0] : [number] | ||
>0 : 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 {string | number} [T=string] | ||
* @template U - error: Required type parameters cannot follow optional type parameters | ||
* @typedef {[T, U]} F | ||
*/ | ||
|
||
/** | ||
* @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) {} | ||
>f1 : <T, U = T>(a: T, b: U) => void | ||
>a : T | ||
>b : U | ||
|
||
/** | ||
* @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) {} | ||
>f2 : <T extends string | number = string, U>(a: T, b: U) => void | ||
>a : T | ||
>b : U | ||
|
||
/** | ||
* @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) {} | ||
>f3 : <T = U, U = T>(a: T, b: U) => void | ||
>a : T | ||
>b : U | ||
|
Oops, something went wrong.