TS 5.3 で追加された switch (true) での narrowing (型の絞り込み)機能について書きませんか?
https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/
function f(x: unknown) {
switch (true) {
case typeof x === "string":
// 'x' is a 'string'
case Array.isArray(x):
// 'x' is a 'string | any[]'
default:
// 'x' is 'unknown'
}
}
フォールスルーすることで、型が追加されていくところが特徴的な機能。
TS 5.3 で追加された
switch (true)での narrowing (型の絞り込み)機能について書きませんか?https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/
フォールスルーすることで、型が追加されていくところが特徴的な機能。