mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +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/nullable.ts
Normal file
19
editors/code/src/nullable.ts
Normal 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\``);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue