diff --git a/.changeset/view-focus-capture-optional-rn-prop.md b/.changeset/view-focus-capture-optional-rn-prop.md new file mode 100644 index 0000000..dd9f998 --- /dev/null +++ b/.changeset/view-focus-capture-optional-rn-prop.md @@ -0,0 +1,5 @@ +--- +'@plextv/react-native-lightning': patch +--- + +`View`'s `onFocusCapture` type no longer assumes `react-native`'s `ViewProps` declares the prop. react-native-tvos has it, plain react-native doesn't, so the indexed access was a hard `check:types` error for anyone on upstream react-native. Reads the prop only when it's actually present, so both forks typecheck. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3308b8a..7427261 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,5 +34,8 @@ jobs: - name: Lint run: pnpm run lint + - name: Check types + run: pnpm run check:types + - name: Run unit tests run: pnpm run test diff --git a/packages/react-native-lightning/src/exports/View.tsx b/packages/react-native-lightning/src/exports/View.tsx index 19ddde3..b1905b4 100644 --- a/packages/react-native-lightning/src/exports/View.tsx +++ b/packages/react-native-lightning/src/exports/View.tsx @@ -16,6 +16,12 @@ import { useLayoutHandler } from '../hooks/useLayoutHandler'; import type { NativeLightningViewElement } from '../types/NativeLightningViewElement'; import { isFocusActive, shouldRegisterFocus } from './focusableView'; +// react-native-tvos declares onFocusCapture on ViewProps, plain react-native +// doesn't. Generic so the indexed access stays deferred and compiles on both. +type FocusCaptureOf
= 'onFocusCapture' extends keyof P
+ ? P['onFocusCapture']
+ : never;
+
type CombinedProps = Omit<
RNViewProps &
LightningViewElementProps &
@@ -28,7 +34,7 @@ type CombinedProps = Omit<
// intersecting them yields a signature no handler can satisfy. Accept either.
onFocusCapture?:
| FocusableProps['onFocusCapture']
- | RNViewProps['onFocusCapture'];
+ | FocusCaptureOf