or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

android-platform.mdindex.mdios-platform.mdnative-interop.mdnativescript-widgets.md
tile.json

tessl/npm-tns-platform-declarations

Platform-specific TypeScript declarations for NativeScript for accessing native objects

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/tns-platform-declarations@6.5.x

To install, run

npx @tessl/cli install tessl/npm-tns-platform-declarations@6.5.0

index.mddocs/

TNS Platform Declarations

TNS 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.

Package Information

  • Package Name: tns-platform-declarations
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install tns-platform-declarations

Core Imports

Basic Platform Access

/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />

API Level Specific (Android)

// 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" />

Basic Usage

/// <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);

Architecture

TNS Platform Declarations is organized around platform separation and version support:

  • Platform Entry Points: Separate entry points for Android (android.d.ts) and iOS (ios.d.ts) platforms
  • Version Support: Multiple Android API level variants (17-29) with corresponding AndroidX support
  • Framework Coverage: Complete iOS SDK framework declarations (139 frameworks)
  • Memory Management: Built-in functions for native object lifecycle management
  • Type Safety: Full TypeScript definitions ensuring compile-time type checking
  • Interoperability: Rich interop layer for seamless native code integration

Capabilities

Android Platform API

Comprehensive 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;

Android Platform

iOS Platform API

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;

iOS Platform

Native Interoperability

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;
}

Native Interoperability

NativeScript Widgets

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;
  }
}

NativeScript Widgets

Types

Common Types

interface ArrayConstructor {
  create(type: any, count: number): any;
}

declare module native {
  export class Array<T> {
    constructor();
    length: number;
    [index: number]: T;
  }
}

Configuration

TypeScript Configuration

Recommended tsconfig.json settings for using TNS Platform Declarations:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "lib": ["es6", "dom"]
  }
}

Reference Setup

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" />

Performance Considerations

  • Memory Usage: Declaration files are large and memory-intensive
  • CPU Impact: Compilation can be CPU intensive with all declarations
  • Build Optimization: Consider using skipLibCheck: true in TypeScript configuration
  • API Level Selection: Use specific Android API levels instead of default to reduce overhead