Skip to content

fix(types): support ImageRequireSource in ReactVideoSource (#4901)#4904

Closed
vanhci wants to merge 1 commit into
TheWidlarzGroup:support/6.x.xfrom
vanhci:fix/issue-4901-typescript-require
Closed

fix(types): support ImageRequireSource in ReactVideoSource (#4901)#4904
vanhci wants to merge 1 commit into
TheWidlarzGroup:support/6.x.xfrom
vanhci:fix/issue-4901-typescript-require

Conversation

@vanhci
Copy link
Copy Markdown

@vanhci vanhci commented May 20, 2026

Fix: TypeScript type bug in ReactVideoSource (#4901)

Problem: React Native asset require() returns ImageRequireSource (a number), but ReactVideoSource type only accepted string | NodeRequire. The runtime code in Video.tsx already handles numeric asset ids at both source positions, but the TS type didn't reflect this.

Fix: Widen ReactVideoSource to also accept ImageRequireSource directly, matching the documented runtime behavior and the README example.

// Before
export type ReactVideoSource = Readonly<
  Omit<ReactVideoSourceProperties, 'uri'> & {
    uri?: string | NodeRequire;
  }
>;

// After  
export type ReactVideoSource =
  | ImageRequireSource
  | Readonly<
      Omit<ReactVideoSourceProperties, 'uri'> & {
        uri?: string | ImageRequireSource;
      }
    >;

Changed file: src/types/video.ts (support/6.x.x branch)

Testing: This is a pure type-only change. The runtime behavior is already correct (the code in Video.tsx already handles typeof _source === 'number' and typeof _source.uri === 'number').

Fixes #4901

React Native asset require() returns ImageRequireSource (number), but the
ReactVideoSource type only accepted string | NodeRequire. The runtime code in
Video.tsx already handles numeric asset ids at both source positions:
  - typeof _source === 'number'
  - typeof _source.uri === 'number'

This change widens ReactVideoSource to also accept ImageRequireSource
directly, matching the documented runtime behavior and the README example.

Fixes #4901
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

1 participant