mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
81 lines
2.3 KiB
Plaintext
81 lines
2.3 KiB
Plaintext
main.js(47,21): error TS2532: Object is possibly 'undefined'.
|
|
main.js(55,9): error TS2322: Type 'string' is not assignable to type 'number'.
|
|
main.js(64,9): error TS7008: Member 'bar' implicitly has an 'any[]' type.
|
|
|
|
|
|
==== main.js (3 errors) ====
|
|
class C1 {
|
|
constructor() {
|
|
this.foo = [3];
|
|
this.foo = [this.foo[0] * 2];
|
|
this.foo; // number[]
|
|
}
|
|
}
|
|
|
|
class C2 {
|
|
constructor() {
|
|
this.foo = [3];
|
|
this.foo; // number[]
|
|
}
|
|
method1() {
|
|
this.foo = [this.foo[0] * 2];
|
|
}
|
|
}
|
|
|
|
class C4 {
|
|
constructor() {
|
|
this.bar = [];
|
|
this.bar.push("baz");
|
|
this.bar; // string[]
|
|
}
|
|
}
|
|
|
|
// When this.xxx assignment declarations occur only in methods, the declared type of the
|
|
// property is a union of the types of all assigned values, excluding values from self-referential
|
|
// assignments, plus undefined. Local CFA removes the undefined when possible.
|
|
|
|
class C5 {
|
|
method1() {
|
|
this.foo; // number[] | undefined
|
|
this.foo = [3]
|
|
this.foo = [this.foo[0] * 2]
|
|
this.foo; // number[]
|
|
}
|
|
}
|
|
|
|
class C6 {
|
|
method1() {
|
|
this.foo = [3];
|
|
this.foo; // number[]
|
|
}
|
|
method2() {
|
|
this.foo; // number[] | undefined
|
|
this.foo = [this.foo[0] * 2]; // Error: Object is possibly undefined
|
|
~~~~~~~~
|
|
!!! error TS2532: Object is possibly 'undefined'.
|
|
this.foo; // number[]
|
|
}
|
|
}
|
|
|
|
class C7 {
|
|
method1() {
|
|
this.foo = 0;
|
|
this.foo = this.foo + "abc"; // Error, 'string' not assignable to 'number'
|
|
~~~~~~~~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
}
|
|
}
|
|
|
|
// When this.xxx assigmment declarations occur only in methods, an assigned empty array
|
|
// literal value is given type 'any[]'.
|
|
|
|
class C8 {
|
|
method1() {
|
|
this.bar = []; // Error: Implicit any[]
|
|
~~~~~~~~~~~~~
|
|
!!! error TS7008: Member 'bar' implicitly has an 'any[]' type.
|
|
this.bar.push("baz");
|
|
this.bar; // any[]
|
|
}
|
|
}
|
|
|