TypeScriptのよく使う型メモ
2020年11月11日
number
const hoge: number = 3;
Arrayの中に数値
const hoge: number[] = [1];
ネストしたArray
const hoge = [
{foo: 'aaaa'},
{foo: 'bbbb'}
]
const hoge: Array<{foo: string}>;
boolean
const hoge: boolean = true;
string
const hoge: string = 'aaaaa';
function
– numberを渡すとstringが返ってくる
const myFunc = (id: number): string => {
return id ? "hoge" : "foo"
}
– hashを渡すとstringが返ってくる
const myFunc = ({ id }: { id: number }): string => {
return id ? "hoge" : "foo"
}
React
inputのonChangeのevent
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {}}
style
style?: React.CSSProperties;