& { __brand: "Raw" }; const raw: Raw = "password"; // Error // Type 'string' is not assignable to type '{ __brand: "Raw"; }' const raw: Raw = "password" as Raw; const identity = (text: string) => text; identity(rawPassword); Branded Type というテクニック
[__brand]: B }; export type Branded<T, B> = T & Brand<B>; type Raw = Branded<string, "Raw">; 参考⽂献: Improve Runtime Type Safety with Branded Types in TypeScript | egghead.io Branded Type というテクニック
since よりも⼩さい場合に例外を投げる', async () => { const since = new Date(); const until = new Date(0); await expect(update(1, since, until).rejects.toThrow() }); });