const toast = (msg:string) => console.log(msg)
toast.close = () => {}
toast.open = () => {}
このように型推論される
この型定義もできるconst toast: { (msg: string): void; close(): void; open(): void }
type T =
{
(msg: string): void
close: () => void;
open: () => void
};
const toast: T = ...
toast.close
であとから追加してるからtoast: T
の時点ではエラーがでそうなもんだけどちゃんと後の記述も見てくれてエラーが出ないようになってる。