Skip to content

[cli] Make getFlagsSpecification() type safe#11929

Merged
kodiakhq[bot] merged 11 commits intomainfrom
get-flags-specification-type-safe
Aug 13, 2024
Merged

[cli] Make getFlagsSpecification() type safe#11929
kodiakhq[bot] merged 11 commits intomainfrom
get-flags-specification-type-safe

Conversation

@TooTallNate
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate commented Aug 7, 2024

Before

Screenshot 2024-08-12 at 16 44 39

After

Screenshot 2024-08-12 at 16 45 32

NOTE: It would have been nice to use satisfies Command in the command.ts files for this case, but that keyword does not exist with TypeScript 4 which is what we are currently using. I tried updating to TS 5, but was running into issues. So for now the satisfies is omitted.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 7, 2024

🦋 Changeset detected

Latest commit: d23d560

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR


for (const flag of deprecatedFlags) {
if (parsedArguments.flags[flag]) {
// TODO: This behavior should be centralized in `parseArguments`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comment (non-blocking): I like this idea, it goes well with how I want to re-model how we handle deprecation, type-wise.

}
} else {
outputArray.push(buildValueLine(example.value));
outputArray.push(buildValueLine(example.value as string));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (non-blocking): ‏remove type assertion

Is it possible to remove this type assertion?

Copy link
Copy Markdown
Contributor

@erikareads erikareads Aug 13, 2024

Choose a reason for hiding this comment

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

I assume that's because the as const makes those values into literals, so they have to be turned back into strings.

Copy link
Copy Markdown
Member Author

@TooTallNate TooTallNate Aug 13, 2024

Choose a reason for hiding this comment

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

@erikareads is on the right track. For some reason, Array.isArray() was not correctly narrowing the readonly array type (from as const), so TS thinks this line could still be an array type (it can not).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a comment above this line explaining that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added comment in a follow-up PR #11955

@kodiakhq kodiakhq bot merged commit 8e3ded3 into main Aug 13, 2024
@kodiakhq kodiakhq bot deleted the get-flags-specification-type-safe branch August 13, 2024 21:40
TooTallNate added a commit that referenced this pull request Aug 13, 2024
This is a follow-up to #11929 which fixes a couple `@ts-expect-error`
instances by removing the `readonly` attribute from array types so that
it is compatible with the `arg.Spec` type from the "arg" package.
TooTallNate added a commit that referenced this pull request Aug 14, 2024
This is a follow-up to #11929 which fixes a couple `@ts-expect-error`
instances by removing the `readonly` attribute from array types so that
it is compatible with the `arg.Spec` type from the "arg" package.

Also added some comments in a couple places trying to explain how this
complex type works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants