Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00450f0

Browse files
authored
Not all extended types have symbols (microsoft#20827)
1 parent 813864f commit 00450f0

File tree

6 files changed

+114
-1
lines changed

6 files changed

+114
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22743,7 +22743,7 @@ namespace ts {
2274322743
checkTypeAssignableTo(typeWithThis,
2274422744
getTypeWithThisArgument(t, type.thisType),
2274522745
node.name || node,
22746-
t.symbol.flags & SymbolFlags.Class ?
22746+
t.symbol && t.symbol.flags & SymbolFlags.Class ?
2274722747
Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass :
2274822748
Diagnostics.Class_0_incorrectly_implements_interface_1);
2274922749
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
tests/cases/compiler/implementsIncorrectlyNoAssertion.ts(8,7): error TS2420: Class 'Baz' incorrectly implements interface 'Foo & Bar'.
2+
Type 'Baz' is not assignable to type 'Foo'.
3+
Types of property 'x' are incompatible.
4+
Type 'number' is not assignable to type 'string'.
5+
6+
7+
==== tests/cases/compiler/implementsIncorrectlyNoAssertion.ts (1 errors) ====
8+
declare class Foo {
9+
x: string;
10+
}
11+
declare class Bar {
12+
y: string;
13+
}
14+
type Wrapper = Foo & Bar;
15+
class Baz implements Wrapper {
16+
~~~
17+
!!! error TS2420: Class 'Baz' incorrectly implements interface 'Foo & Bar'.
18+
!!! error TS2420: Type 'Baz' is not assignable to type 'Foo'.
19+
!!! error TS2420: Types of property 'x' are incompatible.
20+
!!! error TS2420: Type 'number' is not assignable to type 'string'.
21+
x: number;
22+
y: string;
23+
}
24+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [implementsIncorrectlyNoAssertion.ts]
2+
declare class Foo {
3+
x: string;
4+
}
5+
declare class Bar {
6+
y: string;
7+
}
8+
type Wrapper = Foo & Bar;
9+
class Baz implements Wrapper {
10+
x: number;
11+
y: string;
12+
}
13+
14+
15+
//// [implementsIncorrectlyNoAssertion.js]
16+
var Baz = /** @class */ (function () {
17+
function Baz() {
18+
}
19+
return Baz;
20+
}());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/implementsIncorrectlyNoAssertion.ts ===
2+
declare class Foo {
3+
>Foo : Symbol(Foo, Decl(implementsIncorrectlyNoAssertion.ts, 0, 0))
4+
5+
x: string;
6+
>x : Symbol(Foo.x, Decl(implementsIncorrectlyNoAssertion.ts, 0, 19))
7+
}
8+
declare class Bar {
9+
>Bar : Symbol(Bar, Decl(implementsIncorrectlyNoAssertion.ts, 2, 1))
10+
11+
y: string;
12+
>y : Symbol(Bar.y, Decl(implementsIncorrectlyNoAssertion.ts, 3, 19))
13+
}
14+
type Wrapper = Foo & Bar;
15+
>Wrapper : Symbol(Wrapper, Decl(implementsIncorrectlyNoAssertion.ts, 5, 1))
16+
>Foo : Symbol(Foo, Decl(implementsIncorrectlyNoAssertion.ts, 0, 0))
17+
>Bar : Symbol(Bar, Decl(implementsIncorrectlyNoAssertion.ts, 2, 1))
18+
19+
class Baz implements Wrapper {
20+
>Baz : Symbol(Baz, Decl(implementsIncorrectlyNoAssertion.ts, 6, 25))
21+
>Wrapper : Symbol(Wrapper, Decl(implementsIncorrectlyNoAssertion.ts, 5, 1))
22+
23+
x: number;
24+
>x : Symbol(Baz.x, Decl(implementsIncorrectlyNoAssertion.ts, 7, 30))
25+
26+
y: string;
27+
>y : Symbol(Baz.y, Decl(implementsIncorrectlyNoAssertion.ts, 8, 14))
28+
}
29+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/implementsIncorrectlyNoAssertion.ts ===
2+
declare class Foo {
3+
>Foo : Foo
4+
5+
x: string;
6+
>x : string
7+
}
8+
declare class Bar {
9+
>Bar : Bar
10+
11+
y: string;
12+
>y : string
13+
}
14+
type Wrapper = Foo & Bar;
15+
>Wrapper : Wrapper
16+
>Foo : Foo
17+
>Bar : Bar
18+
19+
class Baz implements Wrapper {
20+
>Baz : Baz
21+
>Wrapper : Wrapper
22+
23+
x: number;
24+
>x : number
25+
26+
y: string;
27+
>y : string
28+
}
29+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare class Foo {
2+
x: string;
3+
}
4+
declare class Bar {
5+
y: string;
6+
}
7+
type Wrapper = Foo & Bar;
8+
class Baz implements Wrapper {
9+
x: number;
10+
y: string;
11+
}

0 commit comments

Comments
 (0)