TypeScript/tests/baselines/reference/jsdocTemplateTagDefault.symbols
Ron Buckton cf787e9bcf
Fix name resolution in typedef and allow defaults for template tags (#45483)
* Fix name resolution in typedef and allow defaults for template tags

* Inline parseBracketNameInTemplateTag

* Update baselines

* Add js declaration emit tests
2021-09-08 17:05:07 -07:00

84 lines
2.2 KiB
Plaintext

=== 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 [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, 48, 12))
>b : Symbol(b, Decl(file.js, 48, 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, 48, 20))
>a : Symbol(a, Decl(file.js, 56, 12))
>b : Symbol(b, Decl(file.js, 56, 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, 56, 20))
>a : Symbol(a, Decl(file.js, 64, 12))
>b : Symbol(b, Decl(file.js, 64, 14))