Skip to content

Instantly share code, notes, and snippets.

@zhaomengru2015
Last active March 19, 2020 10:18
Show Gist options
  • Select an option

  • Save zhaomengru2015/0e0c019eb5e7758cd6199267074842a2 to your computer and use it in GitHub Desktop.

Select an option

Save zhaomengru2015/0e0c019eb5e7758cd6199267074842a2 to your computer and use it in GitHub Desktop.
type vs interface
type PointType = {
x: number
y: number
}
interface ThreeDimesions extends PointType {
z: number
}
interface PointInterface {
x: number
y: number
}
class RectangleType implements PointType {
x = 2
y = 4
}
interface ThreeDimesionsInterface extends PointInterface {
z: number
}
class RectangleInterface implements PointInterface {
x = 3
y = 4
}
interface Box {
height: number
width: number
}
interface Box {
scale: number
}
const box: Box ={height: 5, width: 6, scale: 10}
interface PointInterface {
x: number
y: number
}
type PointType = {
x: number
y: number
}
const getRectangleAreaInterface = (args: PointInterface) =>
args.x * args.y
const getRectangleAreaAliased = (args: PointType) =>
args.x * args.y
getRectangleAreaInterface({ x: 12 })
getRectangleAreaAliased({x:2})
@zhaomengru2015
Copy link
Author

“type aliases cannot extend/implement other types” (implements-extends-types.ts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment