Repository navigation
fix(types): import React in files whose emitted declarations use React.* - #128
Open
david-roper wants to merge 2 commits into
Open
david-roper wants to merge 2 commits into
david-roper wants to merge 2 commits into
Conversation
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.
fix(types): import
Reactin files whose emitted declarations useReact.*following steps provided in #126
Problem
Since 6.18.0, some published
.d.tsfiles referenceReact.*without importing it. For example,dist/components/Checkbox/Checkbox.d.ts:This only resolves if the consumer's program has a global
Reactnamespace, which@types/reactprovides viaexport as namespace React. Consumers without that global getTS2503: Cannot find namespace 'React'. WithskipLibCheck: truethat error is hidden, and the props silently becomeany.Open Data Capture is one such consumer: it overrides
@types/reactwith a vendoredreactpackage whose types have noexport as namespace React. With 6.18.0,apps/webgets 17 ×TS7006(43 ×TS2503withskipLibCheck: false).Cause: #124 (replace
forwardRefwithrefas a prop) moved bareReact.*types fromforwardRefgeneric arguments, which were only used for inference, into parameter annotations. Declaration emit copies parameter annotations as written. Compound components built withObject.assign(Table,Tabs,Select,DropdownMenu,Sheet,HoverCard) inherit the bare references from their subcomponents. In total, 48 of 204 emitted.d.tsfiles were affected.Newly affected in 6.18.0:
Checkbox,DropdownButton,Label,Separator,SliderDropdownMenu.*items,HoverCard.Content,Select.*,Sheet.{Title,Description}Table,Table.*,Tabs,Tabs.*refofTooltip.TriggerForm/FormProps(5 errors) was already affected in 6.17.0.Changes
1. Type-only
Reactimportsimport type * as React from 'react';to the 49 files that useReact.*without importing it: 45 published files plus 4 story/spec files..jsand.cssare byte-identical to before. Only.d.tsfiles (and.js.mapline offsets) change.Table.d.tsnow emitimport("react").ComponentProps<…>.2. Guard against regressions:
pnpm lint:distlibui's own
tsccan't catch this, because@types/reactprovides the global. So this PR addsscripts/check-dist-types.js, which:dist/**/*.d.tswithskipLibCheck: falseexport as namespace React;from@types/reactin memory first, to reproduce a consumer without the globaldistis empty, if no@types/reactfile was read, or if the global wasn't found, so a future change to@types/reactcan't make it pass silentlyIt's wired into:
package.json:"lint:dist": "node scripts/check-dist-types.js"(run afterpnpm build)test.yaml: Build and Check Built Declarations steps after the testsrelease.yaml:build-command: pnpm build && pnpm lint:disttsconfig.json:scripts/**/*is type-checkedVerification
pnpm lint:distmain)pnpm lint,pnpm buildandpnpm test(224/224) pass.Reactglobal can't be found in@types/react.After merging
apps/web(tsc --noEmit -p .) with the published 6.18.1, or with a directfile:dependency. Afile:tarball in the pnpm catalog isn't supported.Separately, adding
export as namespace React;to ODC's vendoredreact@19.xtypes would also fix the third-party bareReact.*in@base-ui/react, which libui can't fix.🤖 Generated with Claude Code
Closes issue #126