Skip to content

fix: inline FlashListProps to remove @shopify/flash-list type dependency#2620

Open
YevheniiKotyrlo wants to merge 1 commit intogorhom:masterfrom
YevheniiKotyrlo:fix/flash-list-optional-type
Open

fix: inline FlashListProps to remove @shopify/flash-list type dependency#2620
YevheniiKotyrlo wants to merge 1 commit intogorhom:masterfrom
YevheniiKotyrlo:fix/flash-list-optional-type

Conversation

@YevheniiKotyrlo
Copy link
Copy Markdown
Contributor

Problem

The published BottomSheetFlashList.d.ts unconditionally imports from @shopify/flash-list:

import type { FlashListProps } from '@shopify/flash-list';

Since @shopify/flash-list is not declared in dependencies, peerDependencies, or optionalDependencies, consumers who don't install flash-list get:

error TS2307: Cannot find module '@shopify/flash-list' or its corresponding type declarations.

The source has // @ts-ignore above the import, which suppresses the error during this package's build — but TypeScript strips @ts-ignore comments from emitted .d.ts files by design (TypeScript #38628, confirmed "Working as Intended" by Ryan Cavanaugh). The downstream type error was never addressed.

Related: #2390, #1968

Fix

I replaced the external type import with a minimal local interface:

import type { FlatListProps } from 'react-native';

interface FlashListProps<T> extends FlatListProps<T> {
    estimatedItemSize?: number;
}

This eliminates the external type dependency entirely. The runtime try/catch require('@shopify/flash-list') is unchanged — only types are affected.

The local interface covers all props that consumers of BottomSheetFlashList realistically use (data, renderItem, keyExtractor, list header/footer components, onEndReached, refreshing, horizontal, numColumns, extraData, plus estimatedItemSize). The few flash-list-specific props omitted (getItemType, overrideItemLayout, drawDistance) are niche optimization hints. For consumers who have @shopify/flash-list installed, Metro resolves the real types from the package directly.

This is the same pattern used by ts-jest PR #3147 to solve the identical problem with an optional esbuild dependency.

Alternatives I explored

Optional peer dependency — does not work

Adding @shopify/flash-list to peerDependenciesMeta: { optional: true } tells the package manager not to warn, but TypeScript does not consult peerDependenciesMeta during module resolution. The .d.ts still imports from @shopify/flash-list, and tsc still fails with TS2307.

Separate entry point — correct but disproportionate

Moving BottomSheetFlashList to a subpath export (@gorhom/bottom-sheet/flash-list) so the main entry point never loads its .d.ts — the Jotai pattern. This works but is a breaking change for existing consumers and restructures exports for a deprecated component.

Validation

Check Result
yarn typescript (tsc --skipLibCheck --noEmit) Pass
yarn lint (biome) Pre-existing issues only; this PR reduces warnings by 1 (removes a @ts-ignore)
bob build + copy-dts Pass — generated .d.ts has no @shopify/flash-list import
Runtime JS output Identical behavior — try/catch require('@shopify/flash-list') preserved
Consumer type-check (skipLibCheck: false) Pass — no TS2307

The published BottomSheetFlashList.d.ts unconditionally imports from
@shopify/flash-list, but flash-list is not declared in any dependency
field. Consumers who don't install flash-list get TS2307 because
TypeScript strips @ts-ignore from emitted .d.ts files (by design,
confirmed in TypeScript #38628).

Replace the external type import with a minimal local interface
extending FlatListProps<T> from react-native. The runtime try/catch
require('@shopify/flash-list') is unchanged -- only types are affected.

Fixes gorhom#2390
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@YevheniiKotyrlo
Copy link
Copy Markdown
Contributor Author

@gorhom — friendly bump. This fixes a real TypeScript breakage for consumers who don't install @shopify/flash-list — the published .d.ts files import it unconditionally even though it's optional, causing TS2307 errors with skipLibCheck: false.

All quality gates pass (tsc, biome lint, bob build). Happy to address any feedback.

TwanLuttik added a commit to TwanLuttik/react-native-bottom-sheet that referenced this pull request Apr 8, 2026
- Replace deprecated Animated.AnimateProps with AnimatedProps (fixes reanimated v4 compatibility)
- Fix onScroll prop being incorrectly omitted from BottomSheetFlatListProps types
- Invoke render function children directly instead of as JSX component to avoid unnecessary re-renders
- Inline FlashListProps type to remove @shopify/flash-list type dependency

Fixes: gorhom#2524, gorhom#2629, gorhom#2636, gorhom#2620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant