Skip to content

Proposal: Support React.Native Platform Specific Code #17681

Description

@alexpomsft

https://facebook.github.io/react-native/docs/platform-specific-code.html#platform-specific-extensions

React.Native's packager allows you to create multiple implementations of a module/file that are specific to target platforms. During build/package time it will pick up the right file based on the target platform. This is super useful.

TypeScript can play reasonably well with this by explicitly including all platform files during the build. However, you lose type safety since TypeScript will only really build against one of the files. For example:

// foo.ts
export const color = "red"
// foo.ios.ts
export const colour = "blue" // British spelling!
// bar.ts
import { color } from "foo"

This will compile correctly, but result in a runtime failure during an iOS execution. It would be great if we could specify the target platform and have the module resolver use that when evaluating which file to load.

Thoughts?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions