Repository navigation
Compile under strict consumer tsconfigs (noUncheckedIndexedAccess, declaration, ES2022 lib) - #215
Merged
Merged
Conversation
Fixes the errors our source produces in shadcn/ui projects that compile with noUncheckedIndexedAccess, declaration emit and an ES2022 lib (the shadcn monorepo template), without changing rendered output: - narrow possibly-undefined array reads (empty-state, input-tags, input-payment, avatar utils, dropdown-button-link, table demo) - export the per-file IllustrationProps so the Illustration map can be named in emitted declarations (TS4023) - replace ES2023+/ES2025 APIs with equivalents available in ES2022 (toReversed in charts-base, Iterator.prototype.toArray in dropdown-button-link) tsconfig now enables noUncheckedIndexedAccess, verbatimModuleSyntax, erasableSyntaxOnly and declaration, and uses the es2022 lib, so these can't regress.
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.
Our source failed to type-check in shadcn/ui projects with stricter tsconfigs (found by the shadcn installation test:
empty-state.tsx,input-payment.tsx,input-tags.tsx,shared-assets/illustrations/index.tsx). This fixes every error the free components produce under the strictest realistic consumer settings, without changing rendered output.Harness
A throwaway project type-checks both repos together (
@/components/*→ react-pro then react, as in the website's tsconfig; TypeScript 6.0.3), combining the shadcnnext-monorepopackages/typescript-config/base.json+react-library.jsonwith create-vite's react-tstsconfig.app.json:strict,noUncheckedIndexedAccess,declaration+declarationMap(emitDeclarationOnly to a scratch dir),isolatedModules,verbatimModuleSyntax,erasableSyntaxOnly,noUnusedLocals,noUnusedParameters,noFallthroughCasesInSwitch,moduleDetection: force,esModuleInterop,resolveJsonModule,skipLibCheck,target: ES2022,lib: [ES2022, DOM, DOM.Iterable](monorepo base; also re-run with the Vite template's ES2023),jsx: react-jsx,module: esnext+moduleResolution: bundler.Not used: the monorepo base's
module/moduleResolution: NodeNext(its extension rules are about the consumer's package layout, not our source), andexactOptionalPropertyTypes(in neither template; 797 errors across both repos, not addressed here).Served files =
components/**,hooks/**,utils/**,examples/**minus*.story.tsx,*.demo.tsx,emails/**; stories/demos are counted separately.Errors in this repo (before → after)
noUncheckedIndexedAccessdeclaration(TS4023)lib: ES2022(toReversed,Iterator.prototype.toArray)(
toArrayis ES2025, so it also failed under the Vite template's ES2023 lib.)What changed
empty-state(slot guard, optional size class),input-tags(last-tag guards),input-payment(namedunknownCardTypefallback instead ofcardTypes[length - 1]),avatar/utils(getInitialsdefault),dropdown-button-link(initial state literal),table.demo.IllustrationPropsinbox/cloud/credit-card/documentsso theIllustrationmap can be named in emitted.d.tsfiles.payload?.toReversed()→[...payload].reverse();keys.keys().toArray()→Array.from(keys).tsconfig.json: addednoUncheckedIndexedAccess,verbatimModuleSyntax,erasableSyntaxOnly,declaration(reports TS4023 even withnoEmit, checked by reverting one export), andlibesnext→es2022, so these can't regress.No
!,anyor@ts-ignore. The only runtime differences are in inputs that used to throw (e.g.getInitials("Olivia")returned"O" + crash; now"O").Verification
bun run test(tsc with the new flags, ESLint, Prettier): passes.Companion PR: untitleduico/react-pro (same branch name). Once both land, the website's generated registry manifests need a refresh.
🤖 Generated with Claude Code