mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
editor/code: Enable noUncheckedIndexedAccess
ts option
https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
This commit is contained in:
parent
bb35d8fa8e
commit
72a3883a71
14 changed files with 124 additions and 52 deletions
19
editors/code/src/undefinable.ts
Normal file
19
editors/code/src/undefinable.ts
Normal 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\``);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue