nicenote/docs/interview/typescript.md
2024-01-15 22:23:10 +08:00

777 B
Raw Permalink Blame History

nav group
title path
面试 /interview
title order
💊 面试题库 7

Typescript

目前市面上比较流行的 js 的超集,目的是为了让 js 更加的严格,向强类型的语言看齐,同时为了后期维护上的便利。

interface 和 type 的区别

interface 更偏向结构定义type 更偏向数据之间的关系

  1. 两者继承的方式不同
interface App extends Module {}

type App = Module & { name: string };
  1. type 可以声明基本数据类型、联合类型、元祖类型interface 不能
type Name = string;

type Pet = Dog | Cat;

type PetList = [Dog, Cat];
  1. type 可以使用 typeof 获取类型interface 不行
const Name = 'nicenote';

type Iname = typeof Name;