TypeScript part4at TECH
TypeScript part4 - 暇つぶし2ch165:デフォルトの名無しさん
22/06/29 20:00:27.28 NKfPTkof.net
質問です。
type t = (a: string) => string;
const f: t = (a) => false;
console.log(f('x'));
で false のところで、
Type 'boolean' is not assignable to type 'string'.ts(2322)
になりますが、
・type t = ... を書き換えてはいけない
・const f の実装を
 const f: t = (a) => <string><unknown>false;
 のように書き換えてはいけない
・// @ts-ignore
 を使ってはいけない。
という縛りで、例えばですが、
type t = (a: string) => string;
overwrite type t = (a: string) => string | boolean;
const f: t = (a) => false;
console.log(f('x'));
のように同名の型のまま戻り値の定義を書き換えるということはできるのでしょうか?
(overwrite type...は、そんな文法は無く、仮想の方法です。)
また、型定義と型指定部分だけ書き換え不可としたら、普通は、
<string><unknown>false;
// @ts-ignore
どちらで乗り切るのでしょうか?


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch