|
| 1 | +=== tests/cases/conformance/jsdoc/file.js === |
| 2 | +/** |
| 3 | + * @template {string | number} [T=string] - ok: defaults are permitted |
| 4 | + * @typedef {[T]} A |
| 5 | + */ |
| 6 | + |
| 7 | +/** @type {A} */ // ok, default for `T` in `A` is `string` |
| 8 | +const aDefault1 = [""]; |
| 9 | +>aDefault1 : Symbol(aDefault1, Decl(file.js, 6, 5)) |
| 10 | + |
| 11 | +/** @type {A} */ // error: `number` is not assignable to string` |
| 12 | +const aDefault2 = [0]; |
| 13 | +>aDefault2 : Symbol(aDefault2, Decl(file.js, 8, 5)) |
| 14 | + |
| 15 | +/** @type {A<string>} */ // ok, `T` is provided for `A` |
| 16 | +const aString = [""]; |
| 17 | +>aString : Symbol(aString, Decl(file.js, 10, 5)) |
| 18 | + |
| 19 | +/** @type {A<number>} */ // ok, `T` is provided for `A` |
| 20 | +const aNumber = [0]; |
| 21 | +>aNumber : Symbol(aNumber, Decl(file.js, 12, 5)) |
| 22 | + |
| 23 | +/** |
| 24 | + * @template T |
| 25 | + * @template [U=T] - ok: default can reference earlier type parameter |
| 26 | + * @typedef {[T, U]} B |
| 27 | + */ |
| 28 | + |
| 29 | +/** |
| 30 | + * @template {string | number} [T] - error: default requires an `=type` |
| 31 | + * @typedef {[T]} C |
| 32 | + */ |
| 33 | + |
| 34 | +/** |
| 35 | + * @template {string | number} [T=] - error: default requires a `type` |
| 36 | + * @typedef {[T]} D |
| 37 | + */ |
| 38 | + |
| 39 | +/** |
| 40 | + * @template {string | number} [T=string] |
| 41 | + * @template U - error: Required type parameters cannot follow optional type parameters |
| 42 | + * @typedef {[T, U]} E |
| 43 | + */ |
| 44 | + |
| 45 | +/** |
| 46 | + * @template {string | number} [T=string] |
| 47 | + * @template U - error: Required type parameters cannot follow optional type parameters |
| 48 | + * @typedef {[T, U]} F |
| 49 | + */ |
| 50 | + |
| 51 | +/** |
| 52 | + * @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. |
| 53 | + * @template [U=T] |
| 54 | + * @typedef {[T, U]} G |
| 55 | + */ |
| 56 | + |
| 57 | +/** |
| 58 | + * @template T |
| 59 | + * @template [U=T] - ok: default can reference earlier type parameter |
| 60 | + * @param {T} a |
| 61 | + * @param {U} b |
| 62 | + */ |
| 63 | +function f1(a, b) {} |
| 64 | +>f1 : Symbol(f1, Decl(file.js, 12, 20)) |
| 65 | +>a : Symbol(a, Decl(file.js, 54, 12)) |
| 66 | +>b : Symbol(b, Decl(file.js, 54, 14)) |
| 67 | + |
| 68 | + /** |
| 69 | + * @template {string | number} [T=string] |
| 70 | + * @template U - error: Required type parameters cannot follow optional type parameters |
| 71 | + * @param {T} a |
| 72 | + * @param {U} b |
| 73 | + */ |
| 74 | +function f2(a, b) {} |
| 75 | +>f2 : Symbol(f2, Decl(file.js, 54, 20)) |
| 76 | +>a : Symbol(a, Decl(file.js, 62, 12)) |
| 77 | +>b : Symbol(b, Decl(file.js, 62, 14)) |
| 78 | + |
| 79 | +/** |
| 80 | + * @template [T=U] - error: Type parameter defaults can only reference previously declared type parameters. |
| 81 | + * @template [U=T] |
| 82 | + * @param {T} a |
| 83 | + * @param {U} b |
| 84 | + */ |
| 85 | +function f3(a, b) {} |
| 86 | +>f3 : Symbol(f3, Decl(file.js, 62, 20)) |
| 87 | +>a : Symbol(a, Decl(file.js, 70, 12)) |
| 88 | +>b : Symbol(b, Decl(file.js, 70, 14)) |
| 89 | + |
0 commit comments