Frontend Weekly 2023-11-24
TypeScript 5.3、Git 2.43、Firefox 120.0について紹介する。
TypeScript 5.3
2023年11月20日にTypeScript 5.3がリリースされました。
https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/
新たな構文のサポートに加えて、JSDoc解析をスキップすることによる最適化やパッケージの重複を避けることによるパッケージサイズの削減なども行われました。
Import Attributes
Stage 3のImport Attributesがサポートされました。
https://github.com/tc39/proposal-import-attributes
これによりモジュールの形式をランタイムに提供できるようになります。
import obj from "./something.json" with { type: "json" };
import * as foo from "./foo.js" with { type: "fluffy bunny" };
const obj = await import("./something.json", {
with: { type: "json" },
});
switch(true) Narrowing
switch (true)
内の各case
句に基づいて型の絞り込みをできるようになりました。
function f(x: unknown) {
switch (true) {
case typeof x === "string":
// 'x' is a 'string' here
console.log(x.toUpperCase());
// falls through...
case Array.isArray(x):
// 'x' is a 'string | any[]' here.
console.log(x.length);
// falls through...
default:
// 'x' is 'unknown' here.
// ...
}
}
Narrowing On Comparisons to Booleans
true
または false
と直接比較した場合でも、絞り込みが出来るようになりました。
interface A {
a: string;
}
interface B {
b: string;
}
type MyType = A | B;
function isA(x: MyType): x is A {
return "a" in x;
}
// <=5.2
function someFn(x: MyType) {
if (isA(x)) {
console.log(x.a); // works!
}
}
// <=5.2
function someFn(x: MyType) {
if (isA(x) === true) {
console.log(x.a); // not works
}
}
// 5.3
function someFn(x: MyType) {
if (isA(x) === true) {
console.log(x.a); // works!
}
}
Git 2.43
2023年11月20日にGit 2.43がリリースされました。
https://github.blog/2023-11-20-highlights-from-git-2-43/
リバートコミットをリバートした際のコミットメッセージのRevert RevertからReapplyになりました。
$ git revert --no-edit HEAD >/dev/null
$ git revert --no-edit HEAD >/dev/null
$ git log --oneline
- a300922 (HEAD -> main) Revert: "Revert: "fix bug""
+ a300922 (HEAD -> main) Reapply "fix bug"
0050730 Revert "fix bug"
b290810 fix bug
巨大なリポジトリを扱う際に、Blobを必要に応じて取得するBlobless cloneを実行したい場合があります。
git clone --filter=blob:none git@github.com:git/git.git
これを通常のローカルリポジトリに後から適用できるようになりました。
% git repack -ad --filter=blob:none --filter-to=pack --no-write-bitmap-index
% git config remote.origin.promisor true
% git config remote.origin.partialclonefilter blob:none
他にも1MiB未満のBlobのみフィルタリングして取得するといったことも出来ます。
git repack -ad --filter='blob:limit=1m' --filter-to=pack
Firefox 120.0
2023年11月21日にFirefox 120.0がリリースされました。
https://www.mozilla.org/en-US/firefox/120.0/releasenotes/
トラッキングコードを削除したリンクをコピーする機能が追加されました。またWebAssembly GCが有効になりました。