Repository navigation
docs: drop return global.__native(this) from Android subclass examples - #206
Open
edusperoni wants to merge 2 commits into
Open
edusperoni wants to merge 2 commits into
edusperoni wants to merge 2 commits into
Conversation
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.
Pre-merge checks:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 JSthiswith__container__and returns the real native instance.__native(x)only unwraps objects that carry__container__._super.call(this); return __native(this);, sothiswas the container and the call was needed.var _this = _super.call(this) || this; ... return global.__native(_this);._thisis 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.__nativefor backward compatibility (internal/ts_helpers.jsin 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 calledsuper(). 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 thesuper()+__nativeconstructors from the twoMyVersatileCopyWriterexamples.content/public/assets/agentic/NATIVESCRIPT.md: removed the constructor from theMyButtonexample and added an explicit instruction not to addreturn global.__native(this), since agents have likely seen the old pattern elsewhere.Verification
npm run build(vitepress) succeeds, and the new tip renders.prettier --checkandtextlintfind nothing new in the changed files.npm run lint:formatalready fails onmainbecause of two unrelated files (content/configuration/vite.md,vite-framework-flavors.md), andNATIVESCRIPT.mdwas already unformatted before this change.A second commit runs prettier on
content/configuration/vite.mdandvite-framework-flavors.md. They were unformatted onmain, which made thelint:formatstep (and so thebuildcheck) fail on every PR. It changes formatting only.