[cli] Make getFlagsSpecification() type safe#11929
Conversation
🦋 Changeset detectedLatest commit: d23d560 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen 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` |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
suggestion (non-blocking): remove type assertion
Is it possible to remove this type assertion?
There was a problem hiding this comment.
I assume that's because the as const makes those values into literals, so they have to be turned back into strings.
There was a problem hiding this comment.
@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).
There was a problem hiding this comment.
Can we add a comment above this line explaining that?
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.
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.
Before
After