GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: scoped platform API types by NathanWalker · Pull Request #45 · NativeScript/rfcs

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Dec 26, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

See RFC for details. In summary:

Historically NativeScript has always provided platform API types on the global scope, for example:

// available anywhere you type
NSString. 
java.

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'

C. import specifiers

See how Node is handling here, eg ... from 'node:fs'

Prior Art: nodejs/node#43413

// esm:
import { NSString } from 'native:Foundation';
// commonjs:
const NSString = require('native:Foundation').NSString;

For third party vendors:

// Objective C/Swift
import { LOTAnimationView } from 'native:Lottie';

// Java/Kotlin
import { LottieAnimationView } from 'native:com.airbnb.lottie';

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

NathanWalker reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@NathanWalker
feat: scoped platform API types
6b59047
@cla-bot cla-bot Bot added the cla: yes label Dec 26, 2022
NathanWalker added 2 commits December 26, 2022 11:46
@NathanWalker
chore: cleanup
68a5d6c
@NathanWalker
chore: cleanup
832d367
@rigor789

rigor789 commented Dec 27, 2022

Copy link
Copy Markdown
Member

Thanks for bringing this up as an RFC! There are many related topics that this can start a conversation around.

I'm not entirely sold on such a big shift (with either option). I feel like it's a big mental shift to require thinking about imports, plus all content that includes example code would technically become incorrect even more so than it currently is (lot's of tns-core-modules/* out there in the wild).

The other side to this is more on the technical level. Types currently reflect how the runtimes work, moving types into deeper imports would require changes to both the build tooling and the runtimes to support, since this wouldn't purely be a typing/TypeScript change. Supporting both current and the proposed syntax at the same time would increase the maintenance overhead of the runtimes.

However, I think our types could be optimized, especially on android. Pairing them down to less, and perhaps more concise/better TypeScript declarations would be a huge step forward. For example, we could start dropping all but latest API versions from the types package (iOS already does this). This would greatly reduce the overhead of all these dts files in editors. Another point of optimization would be to correctly group namespaces/modules instead of re-declaring them multiple times (on the dts-generator side).

Currently, the dts-generator outputs in this format:

declare module android {
  export module R { /* ... */ }
  /* ... */
}
declare module android {
  export module accessibilityservice { /* ... */ }
  /* ... */
}
declare module android {
  // ...
}
declare module android {
  // ...
}

Notice how we have multiple declare module android { blocks - these could all be grouped together.


On Android/java code is organized into packages, however symbols can be "exported" at any level and in those cases you would be required to import from different levels individually.

import { LottieAnimationView } from 'native:com.airbnb.lottie';
import { LottieCallback } from 'native:com.airbnb.lottie.callback';

Not sure if this would be a "con", just thought I'd mention.


Finally, a few remarks/nits:

It's long been debated and even attacked as to whether platform API types should be on the global scope.

I haven't really noticed this being debated, though it does occasionally surprise people that they don't need to import anything to access android. for example.

This would improve developer experience and help the TSC optimize various compiler behaviors.

I think it would be useful to elaborate on how this would affect dx and what optimizations would be possible on the compiler level (I presume easier metadata filtering for example).

is it more clear or less clear

At first it feels less clear to me, however I'm open to try a minimal POC version (purely based on types, not necessarily functional) in my editor to feel it out.

mukaschultze, NathanWalker, and jcassidyav reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ammarahm-ed

ammarahm-ed commented Mar 1, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Has anyone thought about re-exporting globals as scoped imports? That would not require any changes in the runtime or build tooling plus allow us to migrate from global to scoped imports in a step by step process.

For example a module "ns-string"

export const NSString = globalThis.NSString;

declare module "ns-string" {
     NSString: globalThis.NSString
}

We can customize the metadata generators to generate these single module files for each api with the above format which can be imported in code editors.

And you can use it as

import { NSString } from "ns-string";

const val = NSString.alloc().init();

This would simplify metadata filtering a lot probably. And i think it's simple to do.

vallemar reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@NathanWalker NathanWalker mentioned this pull request Oct 14, 2026
Module-scope the platform type surface: make @nativescript/types export ObjC/Java names instead of declaring them ambient NativeScript/NativeScript#11524
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@NathanWalker @rigor789 @ammarahm-ed
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.