Objects / Functions
, 不过它们语法不同。Interface:
interface Point0 {x: number;y: number;}interface SetPoint0 {(x: number, y: number): void}
Type:
type Point1 = {x: number;y: number;}type SetPoint1 = (x: number, b: number) => void
继承自 Interface:
interface PartialPointX0 { x: number }interface Point extends PartialPointX0 { y: number }interface PartialPointX3 { x: number }type PointX1 = PartialPointX3 & { y: number }
继承自 Type:
type PartialPointX1 = { x: number }type PointX1 = PartialPointX1 & { y: number }type PartialPointX2 = { x: number }interface Point extends PartialPointX2 { y: number }
primitives
, unions
以及 tuples
类型。// primitivetype Name = string;// uniontype Point = string | number// tupletype Data = [string, number]
interface Point { x: number }interface Point { y: number }const point: Point = { x: 1, y: 2 }