TypeScript

特定のプロパティを削除したい場合はOmitを使います。

type T1 = { hoge: string foo: number bar: boolean}type T2 = Omit<T1, 'foo'& ...

TypeScript

以下の二つの型があります。

type Hoge = { hoge: string}type Foo = { foo: number}

この二つの型のプロパティ名のUnionを取得したいとします。

"hoge& ...

TypeScript

Hoge型のhogeとbarの型をUnionで取得したい。

type Hoge = { hoge: string foo: number bar: boolean}type Hoge2 = Hoge //string | boo ...

TypeScript

Hoge型があります。

type Hoge = { foo: string, bar: string,};

このHogeがもつプロパティをすべてオプショナルにする場合、Partial を使います。

type Parti ...

TypeScript, 覚書

覚書です。

const createAction = <I extends Q, Q, O>( input: Q, guard: (x: Q) => x is I, converter: (_: I) => ...

TypeScript

const convertAge = (age: number | undefined): any => { if(isAge(age)){ return age + '';//ここのageはnumberになる } r ...

TypeScript, プログラミング入門

TypeScirptでは、条件文でin演算子を使った時にも型ガードとして利用できます。

型ガードとは、条件ブロック内でオブジェクトの型を制限できることです。

以下のコードをみてみます。

type Hoge ...

TypeScript

TypeScriptでは以下のように型が一致している場合にはエラーにはならない。

type Name = stringtype Id = stringconst myName: Name = 'tamibouz' ...

TypeScript

Hogeは、第一引数に変換したいオブジェクト型を受け取り、すべてのプロパティの値の型を第二引数にしたオブジェクト型を返す。

//第一引数に指定した型のすべてのプロパティの型をTYPEにするtype Hoge<T exten ...

TypeScript, 覚書

io-tsを使用する

新しいプロジェクトを作成し、typescript、io-ts、fp-ts を install します。

$ mkdir iots-test$ cd iots-test$ npm init -y$ npm in ...