diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-11 14:26:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-11 14:26:17 +0100 |
commit | 372414d27b41f60142f6c01fd48746a36e71f392 (patch) | |
tree | f6ee7802c775681ff6269000222aa322eeac7b10 | |
parent | 0679d8cbe7acc5221d985e6d4187d6df293bd9d5 (diff) | |
parent | 12e23bd60b9c3dde24bb9fa597ad88705abd2b76 (diff) |
Merge #3942
3942: vscode: fix typing bug in config r=matklad a=Veetaha
I noticed that the type of nullable properties in config is actually non-nullable
![Screenshot from 2020-04-11 15-29-45](https://user-images.githubusercontent.com/36276403/79043702-6a686d80-7c09-11ea-9ae8-f1a777c7d0f2.png)
Co-authored-by: veetaha <[email protected]>
-rw-r--r-- | editors/code/src/config.ts | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 21c1c9f23..35a05131c 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -66,23 +66,44 @@ export class Config { | |||
66 | return vscode.workspace.getConfiguration(this.rootSection); | 66 | return vscode.workspace.getConfiguration(this.rootSection); |
67 | } | 67 | } |
68 | 68 | ||
69 | get serverPath() { return this.cfg.get<null | string>("serverPath")!; } | 69 | /** |
70 | get channel() { return this.cfg.get<UpdatesChannel>("updates.channel")!; } | 70 | * Beware that postfix `!` operator erases both `null` and `undefined`. |
71 | get askBeforeDownload() { return this.cfg.get<boolean>("updates.askBeforeDownload")!; } | 71 | * This is why the following doesn't work as expected: |
72 | get traceExtension() { return this.cfg.get<boolean>("trace.extension")!; } | 72 | * |
73 | * ```ts | ||
74 | * const nullableNum = vscode | ||
75 | * .workspace | ||
76 | * .getConfiguration | ||
77 | * .getConfiguration("rust-analyer") | ||
78 | * .get<number | null>(path)!; | ||
79 | * | ||
80 | * // What happens is that type of `nullableNum` is `number` but not `null | number`: | ||
81 | * const fullFledgedNum: number = nullableNum; | ||
82 | * ``` | ||
83 | * So this getter handles this quirk by not requiring the caller to use postfix `!` | ||
84 | */ | ||
85 | private get<T>(path: string): T { | ||
86 | return this.cfg.get<T>(path)!; | ||
87 | } | ||
88 | |||
89 | get serverPath() { return this.get<null | string>("serverPath"); } | ||
90 | get channel() { return this.get<UpdatesChannel>("updates.channel"); } | ||
91 | get askBeforeDownload() { return this.get<boolean>("updates.askBeforeDownload"); } | ||
92 | get traceExtension() { return this.get<boolean>("trace.extension"); } | ||
93 | |||
73 | 94 | ||
74 | get inlayHints() { | 95 | get inlayHints() { |
75 | return { | 96 | return { |
76 | typeHints: this.cfg.get<boolean>("inlayHints.typeHints")!, | 97 | typeHints: this.get<boolean>("inlayHints.typeHints"), |
77 | parameterHints: this.cfg.get<boolean>("inlayHints.parameterHints")!, | 98 | parameterHints: this.get<boolean>("inlayHints.parameterHints"), |
78 | chainingHints: this.cfg.get<boolean>("inlayHints.chainingHints")!, | 99 | chainingHints: this.get<boolean>("inlayHints.chainingHints"), |
79 | maxLength: this.cfg.get<null | number>("inlayHints.maxLength")!, | 100 | maxLength: this.get<null | number>("inlayHints.maxLength"), |
80 | }; | 101 | }; |
81 | } | 102 | } |
82 | 103 | ||
83 | get checkOnSave() { | 104 | get checkOnSave() { |
84 | return { | 105 | return { |
85 | command: this.cfg.get<string>("checkOnSave.command")!, | 106 | command: this.get<string>("checkOnSave.command"), |
86 | }; | 107 | }; |
87 | } | 108 | } |
88 | } | 109 | } |