nativescript-tslib
为 NativeScript 项目添加对 tslib 辅助工具的支持
npm i --save nativescript-tslib

nativescript 的 tslib

tslib 是 TypeScript 的运行时库,包含所有 TypeScript 辅助函数。

不幸的是,仅仅导入 tslib 就会破坏 NativeScript 项目。

此插件解决了这个问题。

使用方法

安装模块

npm i --save nativescript-tslib

编辑:app/main.ts

import 'nativescript-tslib'; // <-- Add this

// this import should be first in order to load some required settings (like globals and reflect-metadata)
import { platformNativeScriptDynamic } from 'nativescript-angular/platform';

import { AppModule } from './app.module';

// A traditional NativeScript application starts by initializing global objects, setting up global CSS rules, creating, and navigating to the main page.
// Angular applications need to take care of their own initialization: modules, components, directives, routes, DI providers.
// A NativeScript Angular app needs to make both paradigms work together, so we provide a wrapper platform object, platformNativeScriptDynamic,
// that sets up a NativeScript application and can bootstrap the Angular framework.
platformNativeScriptDynamic().bootstrapModule(AppModule);

您可以在 tsconfig.json 中启用 importHelpers,但如果您扩展了 native-classes,可能会破坏您的应用程序。

替代方案

您可以将 tsconfig.json 的目标设置为 es6,但这样您就不能在项目中扩展 native 类。