NativeScript 类型

NativeScript Typings

我正在学习 TypeScript 中的 NativeScript 入门教程: http://developer.telerik.com/featured/getting-started-nativescript/

在一段代码中,我看到:

exports.loadSignUpView = function(args) {
    page = args.object;

    page.bindingContext = journeyInfo;
}

经过一番研究,我能够将 args 输入为

import app = require("application");
exports.loadSignUpView = function(args: app.ApplicationEventData) {
     //...
}

但这仍然无法帮助我键入上面的页面对象,它具有 bindingContext 属性。页面对应的TypeScript类型是什么?

页面类型在"ui/page"模块中定义,loaded事件的参数类型是EventData(来自"data/observable"模块)。 所以你可以这样做:

import observable = require("data/observable");
import pages = require("ui/page");

// Event handler for Page "loaded" event attached in main-page.xml
export function loadSignUpView (args: observable.EventData) {
    // Get the event sender
    var page = <pages.Page>args.object;
}

一些帮助您入门的有用提示:

  1. NativeScript 有 TypeScript support build in since the 1.5 release. You can now use the NativeScript CLI to setup typescript project. You can check the documentation 更多。
  2. 文档中有更多最新内容getting-started guide
  3. 文档中的所有代码片段也有 TypeScript 版本,因此您可以在那里看到类型 - 我们喜欢 TypeScript ;)