editor/code: Enable noUncheckedIndexedAccess ts option

https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
This commit is contained in:
Tetsuharu Ohzeki 2023-06-28 04:03:53 +09:00
parent bb35d8fa8e
commit 72a3883a71
14 changed files with 124 additions and 52 deletions

View file

@ -0,0 +1,19 @@
export type NotNull<T> = T extends null ? never : T;
export type Nullable<T> = T | null;
function isNotNull<T>(input: Nullable<T>): input is NotNull<T> {
return input !== null;
}
function expectNotNull<T>(input: Nullable<T>, msg: string): NotNull<T> {
if (isNotNull(input)) {
return input;
}
throw new TypeError(msg);
}
export function unwrapNullable<T>(input: Nullable<T>): NotNull<T> {
return expectNotNull(input, `unwrapping \`null\``);
}