Platform-specific TypeScript declarations for NativeScript for accessing native objects
npx @tessl/cli install tessl/npm-tns-platform-declarations@6.5.0TNS Platform Declarations is a TypeScript declarations library that provides platform-specific type definitions for NativeScript applications. It enables developers to access native Android and iOS APIs with full type safety, offering comprehensive TypeScript declarations for multiple Android API levels (17-29) and complete iOS SDK frameworks.
npm install tns-platform-declarations/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />// For higher Android API levels
/// <reference path="./node_modules/tns-platform-declarations/android-24.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android-29.d.ts" />/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
// Android usage
const permission = android.Manifest.permission.ACCESS_FINE_LOCATION;
const javaObject = new java.lang.Object();
const floatValue = float(3.14);
// iOS usage
const nsObject = new NSObject();
const pointer = new interop.Pointer();
const reference = new interop.Reference<number>(42);
// Memory management
__releaseNativeCounterpart(javaObject);
__releaseNativeCounterpart(nsObject);TNS Platform Declarations is organized around platform separation and version support:
android.d.ts) and iOS (ios.d.ts) platformsComprehensive Android SDK type definitions with support for multiple API levels and AndroidX libraries. Includes native object access, memory management, and NativeScript-specific widgets.
// Main entry point - defaults to API level 17
/// <reference path="./android.d.ts" />
// API level specific variants
/// <reference path="./android-17.d.ts" />
/// <reference path="./android-18.d.ts" />
// ... through android-29.d.ts
// Core Android functions
declare function float(num: number): any;
declare function long(num: number): any;
declare var gc: () => void;
declare function __releaseNativeCounterpart(object: java.lang.Object): void;Complete iOS SDK framework declarations with native interoperability layer. Provides access to all iOS frameworks, memory management utilities, and Objective-C runtime integration.
// Main entry point
/// <reference path="./ios.d.ts" />
// Core iOS functions
declare function __collect(): void;
declare function __releaseNativeCounterpart(object: NSObject): void;
declare function __time(): Number;Advanced native code integration layer providing pointer arithmetic, memory management, type conversion, and native function calls for iOS platform.
declare module interop {
interface Pointer {
new(offset: number);
add(offset: number): Pointer;
subtract(offset: number): Pointer;
toNumber(): number;
}
interface Reference<T> {
value: T;
}
function alloc(size: number): AdoptedPointer;
function free(ptr: Pointer): void;
function sizeof(type: any): number;
}Platform-specific NativeScript widget declarations for Android development, including async utilities for HTTP, file operations, and image processing.
declare module org.nativescript.widgets {
export class CustomTransition extends androidx.transition.Visibility {
constructor(animatorSet: android.animation.AnimatorSet, transitionName: string);
setResetOnTransitionEnd(resetOnTransitionEnd: boolean): void;
getTransitionName(): string;
}
}interface ArrayConstructor {
create(type: any, count: number): any;
}
declare module native {
export class Array<T> {
constructor();
length: number;
[index: number]: T;
}
}Recommended tsconfig.json settings for using TNS Platform Declarations:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"skipLibCheck": true,
"lib": ["es6", "dom"]
}
}Create a reference.d.ts file in your project:
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />skipLibCheck: true in TypeScript configuration