8a05707559
* fix 31995 * revert useless change only for debug. * add test
39 lines
1.3 KiB
Plaintext
39 lines
1.3 KiB
Plaintext
tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInstanceMemberNarrowedWithLoopAntecedent.ts(29,13): error TS2322: Type 'string | number' is not assignable to type 'number'.
|
|
Type 'string' is not assignable to type 'number'.
|
|
|
|
|
|
==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInstanceMemberNarrowedWithLoopAntecedent.ts (1 errors) ====
|
|
// #31995
|
|
type State = {
|
|
type: "numberVariant";
|
|
data: number;
|
|
} | {
|
|
type: "stringVariant";
|
|
data: string;
|
|
};
|
|
|
|
class SomeClass {
|
|
state!: State;
|
|
method() {
|
|
while (0) { }
|
|
this.state.data;
|
|
if (this.state.type === "stringVariant") {
|
|
const s: string = this.state.data;
|
|
}
|
|
}
|
|
}
|
|
|
|
class SomeClass2 {
|
|
state!: State;
|
|
method() {
|
|
const c = false;
|
|
while (c) { }
|
|
if (this.state.type === "numberVariant") {
|
|
this.state.data;
|
|
}
|
|
let n: number = this.state?.data; // This should be an error
|
|
~
|
|
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
|
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
}
|
|
} |