Skip to content

docs: drop return global.__native(this) from Android subclass examples - #206

Merged
NathanWalker merged 2 commits into
NativeScript:mainfrom
edusperoni:docs/drop-global-native
Nov 12, 2026
Merged

NathanWalker merged 2 commits into
NativeScript:mainfrom
edusperoni:docs/drop-global-native

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

The Android subclassing examples end their TypeScript constructors with return global.__native(this), and the agent guidance (assets/agentic/NATIVESCRIPT.md) tells coding agents to do the same. With TypeScript 2.0 and newer this call does nothing.

Why it's a no-op

When a TypeScript-compiled constructor calls a native base class's call/apply, the Android runtime marks the JS this with __container__ and returns the real native instance. __native(x) only unwraps objects that carry __container__.

  • TypeScript < 2.0 emitted _super.call(this); return __native(this);, so this was the container and the call was needed.
  • TypeScript 2.0+ emits var _this = _super.call(this) || this; ... return global.__native(_this);. _this is already the native instance, which never has __container__, so __native(_this) returns it unchanged.

Every current NativeScript project compiles with TypeScript 2.0+, so a constructor only needs super(...), and can be left out if it does nothing else.

The runtime still defines global.__native for backward compatibility (internal/ts_helpers.js in the Android runtime), so existing code that calls it keeps working. This only simplifies the docs; nothing breaks.

Changes

  • content/guide/extending-classes-and-implementing-interfaces-android.md: removed the call and its "necessary when extending TypeScript constructors" comments from the four TypeScript examples. Removed constructors that only called super(). Added a short tip saying the call isn't needed with TypeScript 2.0+ and that existing calls are harmless.
  • content/guide/android-marshalling.md: removed the super() + __native constructors from the two MyVersatileCopyWriter examples.
  • content/public/assets/agentic/NATIVESCRIPT.md: removed the constructor from the MyButton example and added an explicit instruction not to add return global.__native(this), since agents have likely seen the old pattern elsewhere.

Verification

  • npm run build (vitepress) succeeds, and the new tip renders.
  • prettier --check and textlint find nothing new in the changed files. npm run lint:format already fails on main because of two unrelated files (content/configuration/vite.md, vite-framework-flavors.md), and NATIVESCRIPT.md was already unformatted before this change.

A second commit runs prettier on content/configuration/vite.md and vite-framework-flavors.md. They were unformatted on main, which made the lint:format step (and so the build check) fail on every PR. It changes formatting only.

With TypeScript 2.0 and newer the compiled constructor already returns
the native instance from `_super.call(this)`, so `global.__native` is a
no-op. Remove it from the examples, drop constructors that only called
`super()`, and add a short note that existing calls are harmless.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@NathanWalker
NathanWalker merged commit b858d92 into NativeScript:main Nov 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants