Home | Notifications | New Note | Local | Federated | Search | Logout
Note Detail
きゅーけー@tojoqk@mastodon.tojo.tokyo (2025-12-13 13:02:43)
AIにさっきのコードを投げると、{} が特別な場合だから起きるんだ!普通は起きないんだ!変なことしなければTypeScriptは普通は大丈夫なんだ!とうるさいので記事のコード例を少し変えた。
```
const convert = <T, S>(value: T, witness: S): S => {
const obj1 = { a: witness, b: null } satisfies { a: S, b: null };
const obj2 = { a: value, b: null } satisfies { a: T, b: null };
const f = (x: { a: T, b: null }): { b: null } => x;
const obj = { ...obj1, ...f(obj2) } satisfies { a: S };
return obj.a;
};
```
https://qiita.com/tojoqk/items/1e37896757f847c97948
Reply