todays-typescript.pdf

 todays-typescript.pdf

Transcript

  1. 11.

    interface X {! getName(): string;! getAge(): number;! }! ! class

    XImpl implements X {! getName() {return 'Aono';}! getAge() {return 31;}! }!
  2. 13.

    interface M<T> {! getValue(): T;! }! ! class MImpl implements

    M<string> {! getValue(): string {! return 'foobarbaz'! }! }!
  3. 16.

    type B = {! a: number,! b: string! } |

    {! a: string,! b: number! };!
  4. 21.

    const x: {a: string, b: number} = obj;! const y:

    {a: number, b: string} = obj;! ! const x: {! a: MyClass<MyInnerClass<string>>,! ...! } = obj;! const y: {! a: MyClass<MyInnerClass<number>>,! ...! } = obj;!
  5. 24.

    type FetchedPerson = {! [P in Person]: Promise<Person[P]>! };! !

    type FetchedPerson = {! name: Promise<string>;! age: Promise<number>;! }!
  6. 25.

    type Promisify<T> = {! [P in T]: Promise<T[P]>! };! !

    type FetchedPerson = Promisify<Person>;!
  7. 29.

    type MyReturnType<T> = ! T extends (...args: any) => infer

    X? X: T;! ! interface X {! getName(): string! }! ! type R = MyReturnType<X['getName']>! ꟼ侧ך䨱׶⦼׾《䖤
  8. 30.

    type UnPromisifyField<T> = {! [P in keyof T]:! T[P] extends

    Promise<infer X>? UnPromisify<X>! : UnPromisify<T[P]>;! }! ! type UnPromisify<T> =! T extends Promise<infer X>? UnPromisifyField<X>! : UnPromisifyField<T>; Promise׾䒷׏⶟ָׅ
  9. 31.

    type X = {! y: {! value: Promise<string>;! };! z:

    Promise<number>! }! ! type Y = UnPromisify<X>;!
  10. 32.

    type ArrayElementType<T> = T extends Array<infer R>! ? R! :

    T extends ArrayLike<infer R>! ? R! : T extends NodeListOf<infer R> ? R! : T extends NodeList ? Node[] : T;! ꂁ⴨ך銲稆㘗׾《䖤
  11. 34.

    type X = {! a: string;! b: number;! c: string;!

    };! ! type Y = Pick<X, 'a' | 'b'>;!