简体   繁体   中英

NativeScript Typings

I'm working through the NativeScript getting started tutorial in TypeScript: 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

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. What is the TypeScript type that corresponds to the page?

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). 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 . You can now use the NativeScript CLI to setup typescript project. 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 ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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