わいの日記

ありがちエンジニアブログ

TypeScript

TypeScript (Constructor)

こういう差があるんだ。。。 constructorの引数でpublicとかprivateの修飾詞つけると、 わざわざ別に変数宣言しなくてもいいんだ へぇ // これだとこれだとtitleがないよと怒られる // class Category { // constructor(title: string) {} // getInfo(): voi…

TypeScript カスタムエラーの作成の仕方

以下に移転しました exhikkii.com

TypeScript (Type Guards、Discriminated Unions)

TypeScriptいろいろできるなー Type Guards たとえばstring型の数字か,numberの数字を引数に取る想定した場合とかに有効かな const argNumberOrString = (value: string | number): void => { value.toString() // ここはセーフ value.toFixed() // ここでva…

TypeScript (Intersection Types、 Mapped Types)

へぇと思ったので紹介 Interscetion Types 両方引き継ぐことができる でorができるんだから、&も当然っちゃ当然か interface IHoge { hoge(): void } interface IFuga { fuga(): void } // Intersection Types type IHogeFuga = IHoge & IFuga let hogefuga:…

TypeScriptいろいろ(型、継承、Interface、Singleton)

整理整理 Interface 継承 interface IFather { fatherName: string // おとんの名前をstring型 } interface IMother { motherName: string // おかんの名前をstring型 } // IFatherとIMotherを継承するIChildrenを定義 interface IChildren extends IFather,…

( React + TypeScript)event.target.nameとevent.target.valueの型付け

ブログ移転しました exhikkii.com

vue-i18n を TypeScript で静的型付けする

最近の気づきをメモがわりに。vue(正確にはNuxt.js) + TypeScriptのプロジェクトでvue-i18nを導入して国際化対応しました。vue-i18nのセットアップは公式をご参照ください。 https://kazupon.github.io/vue-i18n/ 内容は実際とは違いますが、 やろうとしたこ…