Skip to content
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

storage: Some typing fun #21200

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mvollmer
Copy link
Member

@mvollmer mvollmer commented Oct 31, 2024

No description provided.

@mvollmer
Copy link
Member Author

Somehow TS doesn't allow this:

const items = [];
items.push("123");

TS infers "never[]" as the type for "items" and doesn't allow pushing strings onto it.

But @allisonkarlitskaya says this should work and TS should infer "string[]" as the type, and it does in her experiments.

@@ -23,6 +23,7 @@
"moduleResolution": "node",
"noEmit": true, // we only use `tsc` for type checking
"strict": true,
"noImplicitAny": false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please split this bit out as a separate commit with some verbiage about the impact and trade-offs? Does this apply to *.ts as well? (which we should keep strict), or just to *.js (then that'd be nice)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NACK from me on that one. We definitely don't want to lose this checking in test/static-code.

You could change this in your editor's LSP config, or if we decide that changing it here is indeed the best way, we need to re-enable it again from the tsc run in test/static-code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please split this bit out as a separate commit with some verbiage about the impact and trade-offs?

I hope we don't need to do this globally.

Does this apply to *.ts as well? (which we should keep strict), or just to *.js (then that'd be nice)

It applies to all files, unfortunately. I'll see how to switch this off for individual files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A setting for individual files would be OK. Some kind of comment at the top or so?

@@ -188,6 +188,10 @@ declare module 'cockpit' {
href: string;
go(path: Location | string, options?: { [key: string]: string }): void;
replace(path: Location | string, options?: { [key: string]: string }): void;

encode(path: string | Array<string>,
options? : { [name: string]: string | Array<string> },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also write Record<> for that, I think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just copy/pasting... :-)

@@ -23,6 +23,7 @@
"moduleResolution": "node",
"noEmit": true, // we only use `tsc` for type checking
"strict": true,
"noImplicitAny": false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A setting for individual files would be OK. Some kind of comment at the top or so?

@mvollmer mvollmer added the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Oct 31, 2024
const StorageControl = ({ excuse, excuse_placement, content } :
{ excuse, excuse_placement?, content }) => {
if (!client.superuser.allowed)
return <div />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

@@ -120,13 +119,13 @@
onClick={checked(onClick, setSpinning)}
variant={kind || "secondary"}
isDisabled={!!excuse || (spinner && spinning)}
isLoading={spinner ? spinning : undefined}>
isLoading={spinner ? spinning : false}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

Comment on lines +150 to +153
promise.catch(error => {
dialog_open({
Title: _("Error"),
Body: error.toString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 added lines are not executed by any test.

@mvollmer
Copy link
Member Author

Somehow TS doesn't allow this:

const items = [];
items.push("123");

TS infers "never[]" as the type for "items" and doesn't allow pushing strings onto it.

But @allisonkarlitskaya says this should work and TS should infer "string[]" as the type, and it does in her experiments.

This is caused by the version of "tsc". I had 5.1.3 installed from Fedora repos, which shows this behavior. I also have node_modules/.bin/tsc which is 5,6,3, and infers "any[]"...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-test For doc/workflow changes, or experiments which don't need a full CI run,
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants