タグ

interfaceとtypescriptに関するisdhのブックマーク (2)

  • こわくないTypeScript〜Mapped TypeもConditional Typeも使いこなせ〜 - uhyo/blog

    TypeScriptの型システムは、ユニオン型を始めとする様々な機能を持っているのが特徴的です。 その中でも、mapped typesとconditional typesは高度な機能として知られています。 ところが、その機能の膨大さゆえ、全てを使いこなす必要はない、TypeScriptの複雑な機能を無闇に使うべきではないという言説はたびたび現れます。 そのときに槍玉に上がりやすいのがmapped typesとconditional typesなのです。 筆者は、これらの機能は使えるだけ使い倒すべきであるという考えを持っています。 主張の根幹には、高度な型を使えばより正確にインターフェースを記述することができること、そして正確なインターフェースは使いやすさや正確な型推論結果に貢献することがあります。 正確なインターフェースや型推論結果は、コードの理解速度や開発効率を促進します。 これらは型シ

    こわくないTypeScript〜Mapped TypeもConditional Typeも使いこなせ〜 - uhyo/blog
    isdh
    isdh 2020/09/02
    これを読んでもなおあまりに複雑な型定義はリーダブルではないし、メンテナブルでもないように思う。より正確なインターフェースがバグを防ぐ場合にのみ必要かな
  • TypeScript: type vs interface

    In one of my recent PRs I changed all interfaces to types because there were already more types than interfaces. In the review, I was asked to revert the change. I did it, but as well I wondered what the actual difference between interface and type. Let’s figure out this. I use the latest TS (v3.5.1) for examples in this post. Similarities #Records #

    TypeScript: type vs interface
    isdh
    isdh 2020/06/04
    "Not all of those things were possible in early versions of TS, so people got used to interfaces. But in the latest version of TS, it seems that types are more capable and we can always use them 🤔."もはやinterfaceは有害と言えるんじゃないかな
  • 1