New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
editor/code: Enable --noUncheckedIndexedAccess
& --noPropertyAccessFromIndexSignature
ts option
#15160
editor/code: Enable --noUncheckedIndexedAccess
& --noPropertyAccessFromIndexSignature
ts option
#15160
Conversation
editors/code/tsconfig.json
Outdated
@@ -3,6 +3,7 @@ | |||
"compilerOptions": { | |||
"esModuleInterop": false, | |||
"module": "commonjs", | |||
"moduleResolution": "Node16", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be node16
as in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, there is some reasons:
- Future enhancement. This mode (
node16
) is more natural behavior with the current Node.js' package resolution thannode
(the current default value). And package.json'sexports
would be a wide spreading. I think it's better to enable as early as possible. - Compatibility with
option-t
that depends onexports
field too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry -- I meant node16
instead of Node16
, with a lower-case n
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Mysteriously), it works in either. TypeScript compiler use lower-case but vscode's intellisense uses CamelCase.
I'll address it to lower-case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess either is fine then as long as nothing complains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed the addressed commit: f780810
LGTM except for the r? @Veykril |
bc9df53
to
d1faf5d
Compare
I'm in favor of // simplified for brevity
if (folders.length === 1) {
const folder = unwrapUndefinable(folders[0]);
return folder.uri.fsPath;
} else if (folders.length > 1) {
const folder = unwrapUndefinable(folders[0]);
// comments for justification
return folder.uri.fsPath;
} else {
return "";
} should be // comments for justification
const folder = folders[0];
return folder != null ? folder.uri.fsPath : ""; (I'm aware you mostly preserved the existing code, but we can always make them better ✨ ) Also, I'd rather not pull in another dependency for a utility function or two, but I'll leave the decision to others. |
597c7e5
to
bf2a15a
Compare
I agree here, we only use a single function from that library if I see this right, so if we can't get rid of the call locations for that, can we just hoist that function out into the local source here and drop the dependency? |
https://www.typescriptlang.org/tsconfig#moduleResolution By this change, typescript compiler can read `exports` field in package.json for dependencies. https://nodejs.org/api/packages.html#exports-sugar
bf2a15a
to
edf14df
Compare
Sure. I addressed them and rebased my changeset again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small question, but otherwise this should be good for now. Ideally we should get rid of the unwraps where we can, but most of them seem to be due to ts not being smart enough (like array length checks into indexing still resulting in undefined types)
editors/code/src/commands.ts
Outdated
@@ -129,7 +130,8 @@ export function matchingBrace(ctx: CtxInit): Cmd { | |||
), | |||
}); | |||
editor.selections = editor.selections.map((sel, idx) => { | |||
const active = client.protocol2CodeConverter.asPosition(response[idx]); | |||
const mayBeActive = client.protocol2CodeConverter.asPosition(response[idx]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This confuses me, asPosition
has the following overload asPosition(value: code.Position): proto.Position;
which is what applies here, so why do we unwrap it. It shouldn't be undefined on the type level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At here, response[idx]
should be a ls.Position | undefined
. Then TypeScript selects asPosition(value: ls.Position | undefined | null): code.Position | undefined;
overload than asPosition(value: ls.Position): code.Position;
.
https://github.com/microsoft/vscode-languageserver-node/blob/2041784436fed53f4e77267a49396bca22a7aacf/client/src/common/protocolConverter.ts#L34-L36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update here to:
editor.selections = editor.selections.map((sel, idx) => {
- const mayBeActive = client.protocol2CodeConverter.asPosition(response[idx]);
- const active = unwrapUndefinable(mayBeActive);
+ const position = unwrapUndefinable(response[idx]);
+ const active = client.protocol2CodeConverter.asPosition(position);
const anchor = sel.isEmpty ? active : sel.anchor;
return new vscode.Selection(anchor, active);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh i missed the indexing into the array, that explains it sorry. Typescript inference is weird, given it tells me that indexing results in a non-undefined type ...
Nevertheless this change is better, thanks
edf14df
to
f708453
Compare
Thanks |
☀️ Test successful - checks-actions |
This enables typescript's these option:
--noUncheckedIndexedAccess
null
(orundefined
) strictly just as like checking bystd::option::Option::unwrap()
.--noPropertyAccessFromIndexSignature
bar.foo
access if thebar
type is{ [key: string]: someType; }
.Additionally, to enable
--noUncheckedIndexedAccess
easily, this pull request introduces option-t as a dependency instead of defining a function in this repository likeunwrapUndefinable()
.I'll remove it and define them byself if our dependency management policy is that to avoid to add a new package as possible.