This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Historically NativeScript has always provided platform API types on the global scope, for example:
```
// available anywhere you type
NSString.
java.
```
On the surface it sounds adverse to common JavaScript standards. In practice it's actually not as bad as it sounds mainly because NativeScript is it's own JavaScript runtime so it's rules are customizable and controllable. The problem often comes down to TypeScript types and the fact that you really don't need all the platform API types available in the global scope. NativeScript 8.2 helped this be confining the types and clarifying how you can include more if you want, see [this post](https://blog.nativescript.org/where-did-my-types-go/).
It's long been debated and even attacked as to whether platform API types should be on the global scope.
# Basic example
Progressive ideas around handling platform API types have emerged in 2022 among TSC discussions.
Here are the biggest three options in consideration.
## A. import from runtime packages
```
import { NSString } from '@nativescript/ios'
import { java } from '@nativescript/android'
```
The types could ship with the runtimes themselves either directly or via proxy to `@nativescript/types`.
## B. import from existing types packages explicitly
```
import { NSString } from '@nativescript/types-ios'
import { java } from '@nativescript/types-android'
```
## B. import specifiers
[See how Node is handling here](https://nodejs.org/api/fs.html#file-system), eg `... from 'node:fs'`
import { LottieAnimationView } from 'native:com.airbnb.lottie';
```
# Motivation
This would improve developer experience and help the TSC optimize various compiler behaviors.
# Drawbacks
Why should we *not* do this? Please consider:
- breaking change
- community migration
- is it more clear or less clear
# Alternatives
What [was done in 8.2](https://blog.nativescript.org/where-did-my-types-go/). Pairing down of types to give the developer more control over which they need at anytime.
# Adoption strategy
This approach could be introduced with NativeScript 9.0 purely as an option. Could be a flag enabled in `nativescript.config` which would enable the bundler to be aware of one way or the other. It may not need a flag as it's possible you could use both approaches for awhile.
This would be a slow migration between version 9/10 to 12 likely.
TSC could introduce several migrations for plugin vendors and projects until eventually all that exists is the scoped types.
# Unresolved questions
Other approaches are likely possible.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: scoped platform API types #45
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
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
feat: scoped platform API types #45
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing