|
| 1 | +tests/cases/conformance/jsdoc/b.js(4,13): error TS2352: Type 'number' cannot be converted to type 'string'. |
| 2 | +tests/cases/conformance/jsdoc/b.js(45,16): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'. |
| 3 | + Property 'p' is missing in type 'SomeOther'. |
| 4 | +tests/cases/conformance/jsdoc/b.js(49,19): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'. |
| 5 | + Property 'x' is missing in type 'SomeOther'. |
| 6 | +tests/cases/conformance/jsdoc/b.js(51,17): error TS2352: Type 'SomeDerived' cannot be converted to type 'SomeOther'. |
| 7 | + Property 'q' is missing in type 'SomeDerived'. |
| 8 | +tests/cases/conformance/jsdoc/b.js(52,17): error TS2352: Type 'SomeBase' cannot be converted to type 'SomeOther'. |
| 9 | + Property 'q' is missing in type 'SomeBase'. |
| 10 | +tests/cases/conformance/jsdoc/b.js(58,1): error TS2322: Type '{ p: string | number | undefined; }' is not assignable to type 'SomeBase'. |
| 11 | + Types of property 'p' are incompatible. |
| 12 | + Type 'string | number | undefined' is not assignable to type 'number'. |
| 13 | + Type 'undefined' is not assignable to type 'number'. |
| 14 | +tests/cases/conformance/jsdoc/b.js(66,8): error TS2352: Type 'boolean' cannot be converted to type 'string | number'. |
| 15 | +tests/cases/conformance/jsdoc/b.js(66,15): error TS2304: Cannot find name 'numOrStr'. |
| 16 | +tests/cases/conformance/jsdoc/b.js(66,24): error TS1005: '}' expected. |
| 17 | +tests/cases/conformance/jsdoc/b.js(66,38): error TS2454: Variable 'numOrStr' is used before being assigned. |
| 18 | +tests/cases/conformance/jsdoc/b.js(67,2): error TS2322: Type 'string | number' is not assignable to type 'string'. |
| 19 | + Type 'number' is not assignable to type 'string'. |
| 20 | +tests/cases/conformance/jsdoc/b.js(67,8): error TS2454: Variable 'numOrStr' is used before being assigned. |
| 21 | + |
| 22 | + |
| 23 | +==== tests/cases/conformance/jsdoc/a.ts (0 errors) ==== |
| 24 | + var W: string; |
| 25 | + |
| 26 | +==== tests/cases/conformance/jsdoc/b.js (12 errors) ==== |
| 27 | + // @ts-check |
| 28 | + var W = /** @type {string} */(/** @type {*} */ (4)); |
| 29 | + |
| 30 | + var W = /** @type {string} */(4); // Error |
| 31 | + ~~~~~~~~~~~~~~ |
| 32 | +!!! error TS2352: Type 'number' cannot be converted to type 'string'. |
| 33 | + |
| 34 | + /** @type {*} */ |
| 35 | + var a; |
| 36 | + |
| 37 | + /** @type {string} */ |
| 38 | + var s; |
| 39 | + |
| 40 | + var a = /** @type {*} */("" + 4); |
| 41 | + var s = "" + /** @type {*} */(4); |
| 42 | + |
| 43 | + class SomeBase { |
| 44 | + constructor() { |
| 45 | + this.p = 42; |
| 46 | + } |
| 47 | + } |
| 48 | + class SomeDerived extends SomeBase { |
| 49 | + constructor() { |
| 50 | + super(); |
| 51 | + this.x = 42; |
| 52 | + } |
| 53 | + } |
| 54 | + class SomeOther { |
| 55 | + constructor() { |
| 56 | + this.q = 42; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + function SomeFakeClass() { |
| 61 | + /** @type {string|number} */ |
| 62 | + this.p = "bar"; |
| 63 | + } |
| 64 | + |
| 65 | + // Type assertion should check for assignability in either direction |
| 66 | + var someBase = new SomeBase(); |
| 67 | + var someDerived = new SomeDerived(); |
| 68 | + var someOther = new SomeOther(); |
| 69 | + var someFakeClass = new SomeFakeClass(); |
| 70 | + |
| 71 | + someBase = /** @type {SomeBase} */(someDerived); |
| 72 | + someBase = /** @type {SomeBase} */(someBase); |
| 73 | + someBase = /** @type {SomeBase} */(someOther); // Error |
| 74 | + ~~~~~~~~~~~~~~~~ |
| 75 | +!!! error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'. |
| 76 | +!!! error TS2352: Property 'p' is missing in type 'SomeOther'. |
| 77 | + |
| 78 | + someDerived = /** @type {SomeDerived} */(someDerived); |
| 79 | + someDerived = /** @type {SomeDerived} */(someBase); |
| 80 | + someDerived = /** @type {SomeDerived} */(someOther); // Error |
| 81 | + ~~~~~~~~~~~~~~~~~~~ |
| 82 | +!!! error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'. |
| 83 | +!!! error TS2352: Property 'x' is missing in type 'SomeOther'. |
| 84 | + |
| 85 | + someOther = /** @type {SomeOther} */(someDerived); // Error |
| 86 | + ~~~~~~~~~~~~~~~~~ |
| 87 | +!!! error TS2352: Type 'SomeDerived' cannot be converted to type 'SomeOther'. |
| 88 | +!!! error TS2352: Property 'q' is missing in type 'SomeDerived'. |
| 89 | + someOther = /** @type {SomeOther} */(someBase); // Error |
| 90 | + ~~~~~~~~~~~~~~~~~ |
| 91 | +!!! error TS2352: Type 'SomeBase' cannot be converted to type 'SomeOther'. |
| 92 | +!!! error TS2352: Property 'q' is missing in type 'SomeBase'. |
| 93 | + someOther = /** @type {SomeOther} */(someOther); |
| 94 | + |
| 95 | + someFakeClass = someBase; |
| 96 | + someFakeClass = someDerived; |
| 97 | + |
| 98 | + someBase = someFakeClass; // Error |
| 99 | + ~~~~~~~~ |
| 100 | +!!! error TS2322: Type '{ p: string | number | undefined; }' is not assignable to type 'SomeBase'. |
| 101 | +!!! error TS2322: Types of property 'p' are incompatible. |
| 102 | +!!! error TS2322: Type 'string | number | undefined' is not assignable to type 'number'. |
| 103 | +!!! error TS2322: Type 'undefined' is not assignable to type 'number'. |
| 104 | + someBase = /** @type {SomeBase} */(someFakeClass); |
| 105 | + |
| 106 | + // Type assertion cannot be a type-predicate type |
| 107 | + /** @type {number | string} */ |
| 108 | + var numOrStr; |
| 109 | + /** @type {string} */ |
| 110 | + var str; |
| 111 | + if(/** @type {numOrStr is string} */(numOrStr === undefined)) { // Error |
| 112 | + ~~~~~~~~~~~~~~~ |
| 113 | +!!! error TS2352: Type 'boolean' cannot be converted to type 'string | number'. |
| 114 | + ~~~~~~~~ |
| 115 | +!!! error TS2304: Cannot find name 'numOrStr'. |
| 116 | + ~~ |
| 117 | +!!! error TS1005: '}' expected. |
| 118 | + ~~~~~~~~ |
| 119 | +!!! error TS2454: Variable 'numOrStr' is used before being assigned. |
| 120 | + str = numOrStr; // Error, no narrowing occurred |
| 121 | + ~~~ |
| 122 | +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. |
| 123 | +!!! error TS2322: Type 'number' is not assignable to type 'string'. |
| 124 | + ~~~~~~~~ |
| 125 | +!!! error TS2454: Variable 'numOrStr' is used before being assigned. |
| 126 | + } |
| 127 | + |
| 128 | + |
| 129 | + |
0 commit comments