TypeScript4.5がリリースされたので、追加点を確認しておく。
目次
「Awaited」型の導入
Awaited型はawait,async関数の操作をモデル化する目的で使う。
例)
// A = string
type A = Awaited<Promise<string>>;
// B = number
type B = Awaited<Promise<Promise<number>>>;
// C = boolean | number
type C = Awaited<boolean | Promise<number>>;
node_modules から lib を追加可能に
libを用いることで、標準ライブラリの差し替えが楽になる。
TypeScript 4.5でますます便利に! better-typescript-lib v2
文字列リテラル型の代わりにテンプレートリテラル型を使うことができるようになった
export interface Success {
type: `${string}Success`;
body: string;
}
export interface Error {
type: `${string}Error`;
message: string;
}
export function handler(r: Success | Error) {
// Successで終わる文字列型
if (r.type === "HttpSuccess") {
// rはSuccess型
let token = r.body;
}
}
まだ用途が定まらず理解が難しい。
–module es2022 の追加
es2022がコンパイルオプションとして使えるようになったらしい。 es2022の仕様がまず分かっていないからキャッチアップかなあ。。
その他、諸々あるけどよく分らん。