Upgrade to Pro — share decks privately, control downloads, hide ads and more …

typescript language update

typescript language update

typescript language update

Yosuke Kurami

August 24, 2019
Tweet

More Decks by Yosuke Kurami

Other Decks in Programming

Transcript

  1. ܕνΣοΫͱਪ࿦ w ؔ਺TVNͷ໭Γ஋͸OVNCFSͰ͋Δ͜ͱΛਪ࿦͢Δ function sum(a: number, b: number) { return

    a + b; } console.log(sum(1, sum(1, 1))); // OK // Argument of type '"a"' is not assignable to // parameter of type 'number' console.log(sum('a', 'b'));
  2. 4USVDUVBMTVCUZQJOHT class Hoge { name = "Kurami"; } class Foo

    { name = "Quramy"; } function sayHello(obj: { name: string }) { console.log(obj.name); } sayHello(new Hoge()); sayHello(new Foo()); sayHello(new Error("error"));
  3. w *NQSPWFNBQQFEUZQFNPEJpFST w $POEJUJPOBMUZQFT w 5ZQFJOGFSFODFJODPOEJUJPOBMUZQFT w 6OLOPXOUZQF w 5VQMFTJOSFTUQBSBNFUFSTBOETQSFBEFYQSFTTJPOT

    w .BQQFEUVQMFUZQFT w 4USJDUCJOE DBMM BOEBQQMZNFUIPETJOGVODUJPOT w )JHIFSPSEFSGVODUJPOUZQFJOGFSFODF w *NQSPWFETVQQPSUGPSSFBEPOMZBSSBZTBOEUVQMFT w $POTUDPOUFYUTGPSMJUFSBMFYQSFTTJPOT w "TTFSUJPOJODPOUSPMqPXBOBMZTJT w &UD  
  4. "The goal of TypeScript's type system is to statically model

    patterns in JavaScript in a reasonable way while catching bugs and enforcing correctness" ೥্ظ5ZQF4DSJQUϩʔυϚοϓ IUUQTHJUIVCDPN.JDSPTPGU5ZQF4DSJQUJTTVFT ΑΓൈਮ
  5. *OGFSBOE$BQUVSF w 5͕ؔ਺Ͱ͋Ε͹ɺͦͷ໭Γ஋ͱͯ͠ਪ࿦͞ ΕΔܕ͕3ʹ֨ೲ͞ΕΔ type Return<T> = T extends (...args:

    any[]) => infer R ? R : never; let r: Return<() => number>; // typeof r = number
  6. (FOFSJDSFTUQBSBNFUFST w 3FTU1BSBNFUFSTʹ૯শܕ͕ར༻Մೳʹ w WYʹ͓͚ΔՄม௕Ҿ਺ܕਪ࿦ڧԽͷҰ؀ w declare function curry<T, U

    extends any[], R>( fn: (x: T, ...args: U) => R ): (x: T) => (...args: U) => R; const sum = (a: number, b: number) => a + b; const bound = curry(sum)(1); const x = bound(2); // type of x = number const error = bound("hoge"); // error