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 NotUndefined<T> = T extends undefined ? never : T;
export type Undefinable<T> = T | undefined;
function isNotUndefined<T>(input: Undefinable<T>): input is NotUndefined<T> {
return input !== undefined;
}
export function expectNotUndefined<T>(input: Undefinable<T>, msg: string): NotUndefined<T> {
if (isNotUndefined(input)) {
return input;
}
throw new TypeError(msg);
}
export function unwrapUndefinable<T>(input: Undefinable<T>): NotUndefined<T> {
return expectNotUndefined(input, `unwrapping \`undefined\``);
}