Platform-specific TypeScript declarations for NativeScript for accessing native objects
84
Create a TypeScript utility that helps developers set up proper type references for NativeScript projects targeting both Android and iOS platforms.
Build a module that:
Create a module type-setup.ts that exports functions to generate type reference files:
generateAndroidTypeFile(apiLevel: number): string - Returns the content for an Android type reference file as a string. The apiLevel parameter determines which Android API level to target (17, 21, or 28).
generateIosTypeFile(): string - Returns the content for an iOS type reference file as a string.
The generated file contents should be valid TypeScript declaration files that include the proper syntax to reference platform-specific types.
Create a function validateTypeReferences(fileContent: string, platform: 'android' | 'ios'): boolean that:
@generates
/**
* Generate the content for an Android type reference file
* @param apiLevel - Android API level (17, 21, or 28)
* @returns String content of the TypeScript declaration file
*/
export function generateAndroidTypeFile(apiLevel: number): string;
/**
* Generate the content for an iOS type reference file
* @returns String content of the TypeScript declaration file
*/
export function generateIosTypeFile(): string;
/**
* Validate that a TypeScript declaration file contains proper type references
* @param fileContent - Content of the declaration file to validate
* @param platform - Target platform ('android' or 'ios')
* @returns true if valid, false otherwise
*/
export function validateTypeReferences(fileContent: string, platform: 'android' | 'ios'): boolean;Provides TypeScript declarations for NativeScript platform APIs, enabling access to native Android and iOS APIs with full type safety.
Install with Tessl CLI
npx tessl i tessl/npm-tns-platform-declarationsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10