void 和 undefined 有什么区别?

什么是 never 类型?

下面代码会不会报错?怎么解决?

  1. const obj = {
  2. a: 1,
  3. b: 'string',
  4. };
  5. obj.c = null;

readonly 和 const 有什么区别?

下面代码中,foo 的类型应该如何声明

  1. function foo (a: number) {
  2. return a + 1;
  3. }
  4. foo.bar = 123;

下面代码中,foo 的类型如何声明

  1. let foo = {};
  2. for (let i = 0; i< 100; i++) {
  3. foo[String(i)] = i;
  4. }

实现 MyInterface

  1. interface MyInterface {
  2. ...
  3. }
  4. class Bar implements MyInterface {
  5. constructor(public name: string) {}
  6. }
  7. class Foo implements MyInterface {
  8. constructor(public name: string) {}
  9. }
  10. function myfn(Klass: MyInterface, name: string) {
  11. return new Klass(name);
  12. }
  13. myfn(Bar);
  14. myfn(Foo);

什么是 Abstract Class?

什么是 class mixin, 如何实现?

typeof 关键词有什么用?

keyof 关键词有什么用?

下面代码中,foo 的类型如何声明

  1. function fn(value: number): string {
  2. return String(value);
  3. }
  4. const foo = fn;

下面代码会导致 TS 编译失败,如何修改 getValue 的类型声明。

  1. function getValue() {
  2. return this.value;
  3. }
  4. getValue();

下面是 vue-class-component 的部分代码,解释为什么会有多个 Component 函数的声明,作用是什么?TS 官方文档的那一节有对应的解释文档?

  1. function Component <U extends Vue>(options: ComponentOptions<U>): <V extends VueClass>(target: V) => V
  2. function Component <V extends VueClass>(target: V): V
  3. function Component <V extends VueClass, U extends Vue>(
  4. options: ComponentOptions<U> | V
  5. ): any {
  6. if (typeof options === 'function') {
  7. return componentFactory(options)
  8. }
  9. return function (Component: V) {
  10. return componentFactory(Component, options)
  11. }
  12. }

如何声明 foo 的类型?

  1. const foo = new Map();
  2. foo.set('bar', 1);

如何声明 getProperty,以便能检查出第八行将会出现的运行错误。

  1. function getProperty(obj, key) {
  2. return obj[key].toString();
  3. }
  4. let x = { a: 1, b: 2, c: 3, d: 4 };
  5. getProperty(x, "a");
  6. getProperty(x, "m");

类型声明里 「&」和「|」有什么作用?

下面代码里「date is Date」有什么作用?

  1. function isDate(date: any): date is Date {
  2. if (!date) return false;
  3. return Object.prototype.toString.call(date) === '[object Date]';
  4. }

tsconfig.json 里 —strictNullChecks 参数的作用是什么?

interface 和 type 声明有什么区别?

如何完善 Calculator 的声明。

  1. interface Calculator {
  2. ...
  3. }
  4. let calcu: Calculator;
  5. calcu(2)
  6. .multiply(5)
  7. .add(1)

「import … from」、「 import … = require()」 和 「import(path: string)」有什么区别?

declare 关键字有什么用?

module 关键字有什么用?

如何处理才能在 TS 中引用 CSS 或者 图片使之不报错?

  1. import "./index.scss";
  2. import imgPath from "./home.png";

编写 d.ts 来声明下面的 js 文件

  1. class Foo {
  2. }
  3. module.exports = Foo;
  4. module.exports.Bar = 1;

namespace 和 module 有什么区别

如何实现 module alias?编译成 JS 能否直接运行?

  1. import Bar from '@src/Bar';

哪些声明类型既可以当做 type 也可以当做 value?