Repository navigation
fix: read the type wrapped by TypeScript readonly arrays and tuples - #1213
Open
josunghoon53 wants to merge 1 commit into
Open
josunghoon53 wants to merge 1 commit into
josunghoon53 wants to merge 1 commit into
Conversation
👷 Deploy request for react-docgen pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 3825d58 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Array and tuple types wrapped in the TypeScript
readonlyoperator come out asunknown, becausehandleTSTypeOperatorreturnsnullfor every operator exceptkeyof.readonly string[]accepts the same values asstring[]. So this change reads the wrapped type as is and keeps the original text, withreadonly, only inraw. The result isArrayandtuple, not a differently named type likeReadonlyArray<string>.This was reported in storybookjs/storybook#24097. It is a different case from #1147, which handles
Readonly<T>(aTSTypeReference, not aTSTypeOperator).Changes
react-docgen: when the operator isreadonly,handleTSTypeOperatorreads the wrapped type and setsrawto the original text.@react-docgen/typescript: it runs the same integration cases, so it gets the same handling. Before the change it returned only a string withreadonlyremoved, like{ name: 'string[]' }.typescript/types/readonly-arrays. It coversreadonly string[],readonly [string, number]andreadonly (string | number)[].AI use: I used Claude to find the cause and to draft the fix, the tests and this description. I ran the checks below myself.
Checks
react-docgenand@react-docgen/typescript, and passes after it.pnpm test: all 6 projects pass (react-docgen1,515 passed,@react-docgen/typescript157 passed and 1 skipped).pnpm lint, Prettier on the changed files andgit diff --checkpass.react-docgen, the output forstring[],ReadonlyArray<string>andkeyofis unchanged.