microCMSでブログを作成中です。
参照コードをコピーして作っているのに、TypeScriptエラーに遭遇しますね😅
ガシガシググって解決したことをメモしていきます。
◇non-null assertion
(property) __html: string
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.ts(2322)
ググって辿り着いた回答:
👉 https://stackoverflow.com/questions/54496398/typescript-type-string-undefined-is-not-assignable-to-type-string
You can now use the non-null assertion operator that is here exactly for your use case.
It tells TypeScript that even though something looks like it could be null, it can trust you that it's not:
let name1:string = person.name!;
// ^ note the exclamation mark here
末尾に「!」(non-null assertion operator)を挿入すると、nullに見えるかもしれないけど、nullじゃないからね!と伝えることができる!🤩 のですって✨
◇TypeScriptエラーを無効化する魔法の呪文
👉 次の行を無視
データは渡っている。渡っているじゃないかー😭
とりあえず先に進みたい時の呪文
// @ts-ignore
◇Property does not exist on type 'JSX.IntrinsicElements'
React基本のきの字ですが、コンポーネント名の頭文字は大文字にしましょう。
以上。
めでたし、めでたし✨