Created
October 4, 2020 10:24
-
-
Save hw0k/4afd54421970661666c14f65a7541299 to your computer and use it in GitHub Desktop.
TvI 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type TBase = { | |
t: number; | |
}; | |
interface IBase { | |
i: number; | |
} | |
// extends 사용 | |
interface I1 extends TBase {} | |
interface I2 extends IBase {} | |
// implements 사용 | |
class C1 implements TBase { | |
constructor(public t: number) {} | |
} | |
class C2 implements IBase { | |
constructor(public i: number) {} | |
} | |
// 곱 타입에 대한 extends, implements 사용 | |
type TIntersection = TBase & { | |
t2: number; | |
}; | |
interface I3 extends TIntersection {} | |
class C3 implements TIntersection { | |
constructor(public t: number, public t2: number) {} | |
} | |
interface I4 extends I3 {} | |
class C4 implements I3 { | |
constructor(public t: number, public t2: number) {} | |
} | |
// 오류: 합 타입에 대한 extends, implements 사용 | |
type TUnion = TBase | { | |
u: number; | |
}; | |
interface I5 extends TUnion {} | |
// error(TS2312) | |
// An interface can only extend an object type | |
// or intersection of object types with statically known members. | |
class C5 implements TUnion {} | |
// error(TS2422) | |
// A class can only implement an object type | |
// or intersection of object types with statically known members. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment