TypeScript
function safeJsonParse<T>(jsonString: string): T | null { try { const parsedData = JSON.parse(jsonString); if (typeof parsedData === 'object' && parsedData !== null) { return parsedData as T; } } catch (error) { console.error("JSONパースエラ</t>…
type SampleType = { id: number; name: string; } // 1 type OptionalSampleType1 = Partial<SampleType>; // 2 type OptionalSampleType2 = { [K in keyof SampleType]?: SampleType[K]; }</sampletype>
Next.js (+TypeScript) の環境構築 create-next-app のインストール npm i -g create-next-app プロジェクトの作成 npx create-next-app@latest --typescript 実行 npm run dev ESLint の設定 パッケージのインストール npm i -D eslint 設定 npx eslint --i…
ReactとTypeScriptでカスタムコンポーネントを作っていた際に、通常のHTMLタグの属性の型をどのように持ってくればいいんだろうと思ったので、調べたことをまとめました。 結論:React.ComponentPropsWithoutRef ※もしくは React.ComponentPropsWithRef 以下…