Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Support React.Native Platform Specific Code #17681

Closed
alexpomsft opened this issue Aug 8, 2017 · 4 comments
Closed

Proposal: Support React.Native Platform Specific Code #17681

alexpomsft opened this issue Aug 8, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@alexpomsft
Copy link

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?

@mhegazy
Copy link
Contributor

mhegazy commented Aug 21, 2017

looks like a duplicate of #8328

@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 21, 2017
@eldenpark
Copy link

@mhegazy #8328 has not been solved and this is a LEGITIMATE issue. Files with extensions such as android.ts, ios.ts are not understandably recognized by TS compiler, for example when they are referenced with relative path.

And not only for React Native which promotes file extensions as such, if custom extensions support is added, allowing for example file.test.ts, the entire structure of any typescript could become ever more elegant. Workaround as this is just so painful.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 29, 2017

I do not think there is a simple change that we can do to enable this scenario. The assumptions built on the file extensions goes deep in the system, if we were to enable this scenario we will have to handle this in input files, module resolution, type checking, language service and output generation. again this is not a simple change and rewiring the whole compiler is not something we can take lightly. In #8328 i have outlined a few workarounds.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 14, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants