-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Allow passing additional SupportedExtensions to support React Native .android and .ios module loading #8328
Comments
I think this problem might be better solved with the glob pattern support in tsconfig.json (#5980). Modifying |
Makes sense. Love to see that change going in soon. Currently blocking our RN project. |
Do not think globs will help here. the suggesion in the OP seems like a valid one. we should allow additional lookup locations, so that users can specify that, so the workaround for now, would be create a .d.ts file next to your platform specific modules, something like: /// components/BigButton.d.ts
export * from "./BigButton.ios"; this way your import for |
@mhegazy If the exported types in Is it possible to keep full compile time type checking? |
The compiler does not know that One possible solution here is to have modules implement interfaces, as previously suggested in #420. This will force the compiler to check the shape of the module against an interface. |
here is another workaround to get it to type check today, courtesy of @RyanCavanaugh: import * as ios from "./BigButton.ios";
import * as android from "./BigButton.ios";
declare var _test: typeof ios;
declare var _test: typeof android;
/// export to get the shape of the module
export * from "./BigButton.ios"; now if |
Recommendations here is to use path mapping support, see https://github.com/Microsoft/TypeScript-Handbook/blob/release-2.0/pages/Module%20Resolution.md#path-mapping so your tsconfig.json should contain something like: {
"compilerOptions": {
"paths": {
"*": ["*", "*.ios", "*.android"]
}
}
} this will tell the compiler when resolving an import to
For checking that the different implementation for the modules all have the same shape is tracked by #420 |
closing in favor of #420 |
@mhegazy How can I use the |
Paths is a TS 2.0 feature. documentation is available at: https://github.com/Microsoft/TypeScript-Handbook/blob/release-2.0/pages/Module%20Resolution.md#path-mapping should be merged in main documentation once 2.0 ships out. |
@mhegazy As far as I can tell (when testing it) the path mapping solution only applies to non-relative imports. So I cannot |
Typescript didn't like import('NavigationBackAndroid') because it there isn't a NavigationBackAndroid.ts (microsoft/TypeScript#8328). The workarounds in the issue don't seem right so just used require directly instead of import. Need to import specific files so that they appear in the built package
Having the same issue as @sondremare. Is there an updated recommended way to deal with this particular RN feature? |
Can't believe this issue still persists. The idea of allowing custom extension, or more specifically a filename suffix support, with |
@mhegazy This was closed in favour of #420, but as @sondremare mentioned the |
it is not clear what path mapping means with a relative path. so no plans really., |
i think that at this point the "umbrella" solution is the way to go. having something like this on my index file (that is platform specific) for me makes sense: index.android.ts: |
Note that with webpack |
We are using TypeScript to write our React Native application and encountered an issue with platform specific extensions provided by RN.
React Native will detect when a file has a .ios. or .android. extension and load the right file for each platform when requiring them from other components.
For example, you can have these files in your project:
With this setup, you can just require the files from a different component without paying attention to the platform in which the app will run.
When we use tsc to compile our code, it won't recognize the android or ios platform extension. What about have a
customPlatform
option that's similar toallowJs
that auto prepend the platform name tosupportedTypeScriptExtensions
?The text was updated successfully, but these errors were encountered: