简体   繁体   English

NativeScript打字

[英]NativeScript Typings

I'm working through the NativeScript getting started tutorial in TypeScript: http://developer.telerik.com/featured/getting-started-nativescript/ 我正在研究TypeScript中的NativeScript入门教程: http : //developer.telerik.com/featured/getting-started-nativescript/

In one snippet of code, I see: 在一段代码中,我看到:

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

    page.bindingContext = journeyInfo;
}

After some research I was able to type args as 经过一些研究,我能够将args键入为

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

But that still does not help me type the page object above, which has the bindingContext property. 但这仍然不能帮助我在上面键入具有bindingContext属性的页面对象。 What is the TypeScript type that corresponds to the page? 与页面对应的TypeScript类型是什么?

Page type is defined in the "ui/page" module and the type of the args of the loaded event is EventData (from the "data/observable" module). 页面类型在“ ui / page”模块中定义,已loaded事件的args类型为EventData(来自“ data / observable”模块)。 So you can do something like this: 因此,您可以执行以下操作:

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

Few more useful tips to get you started: 一些更有用的技巧可以帮助您入门:

  1. NativeScript has TypeScript support build in since the 1.5 release . 自1.5版以来, NativeScript具有内置的TypeScript支持 You can now use the NativeScript CLI to setup typescript project. 现在,您可以使用NativeScript CLI来设置打字稿项目。 You can check the documentation for more. 您可以查看文档以了解更多信息。
  2. In the documentation there is more up to date getting-started guide 文档中有更多最新的入门指南
  3. All of the code snippets in the docs have also a TypeScript version so that you can see the typings there - we love typescript ;) 文档中的所有代码段也都具有TypeScript版本,因此您可以在那里查看类型-我们喜欢打字稿;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM