How to develop the micro-typescript program using the _c# tutorial

Source: Internet
Author: User
Tags documentation

Typescript Introduction:

Typescript is a free and open source programming language developed by Microsoft. It is a superset of JavaScript and essentially adds optional static types and class-oriented object-oriented programming to the language. Anders Heilsberg, the chief architect of C #, has worked on the development of typescript.

Typescript extends the syntax of JavaScript, so any existing JavaScript program can work without altering the typescript. Typescript is designed for the development of large applications, and it generates JavaScript at compile time to ensure compatibility.

Typescript supports the header file for adding type information to an existing JavaScript library, extending its benefits for popular libraries such as Jquery,mongodb,node.js and D3.js.

The micro-letter applet is here! The device, which claims to kill the traditional app, is now in beta, but it is now in the official document of the application number, which has been released without an inside number to use the simulator.

Tools and documentation can refer to official documentation: HTTPS://MP.WEIXIN.QQ.COM/DEBUG/WXADOC/DEV/?T=1477926804193

Typescript:

Typescript is the father of C # Anders Hejlsberg Another masterpiece, I believe that like C # Grammar Friends of Typescript will also be fondle admiringly.

Let's talk a little bit about typescript.

TS is an application-level JavaScript development language.

TS are a superset of JavaScript that can be compiled into pure JavaScript.

TS across browsers, across operating systems, across hosts, open source.

TS started in JS, finally JS. Following JavaScript syntax and semantics, it is convenient for countless JavaScript developers.

TS can reuse existing JavaScript code and invoke the popular JavaScript library.

TS can be compiled into concise, simple JavaScript code that runs on any browser, node.js, or any compatible ES3 environment.

Typescript is more productive than JavaScript, including static type checking, symbolic navigation, statement completion, code refactoring, and more.

TS provides classes, modules, and interfaces that make it easier to build components.

By the way, Typescript is only concerned about the content that preceded the JavaScript generation (meaning not to be concerned with the efficiency of the generated JS code), but according to my humble observations and comparisons, The JavaScript code generated by typescript is at least one order of magnitude higher than most of the foreground developers write JavaScript code!!

Typescript Another advantage:

Typescript in the mainstream of the IDE and editor has smart tips!

The important thing to say three times! Write typescript have smart tips! Write typescript have smart tips! Write typescript have smart tips!

Developing micro-credit program with Typescript

Pull a half-day typescript, then how on earth with typescript to develop micro-trust program?

Very simple, and the micro-credit official JavaScript development approach is not much different, is still 4 core files

App: Code an abstract object for the entire application that can set global methods and variables

Page: Pages abstract object, hosting page business logic

Wxml: The structure of the page, equivalent to HTML

JSON: Configuration file

WXSS: The style of the page, equivalent to CSS

Since Tencent currently does not have a typescript version of the API, the Onecode team developed a typescript version of the API type definition file for all of the applet's JavaScript APIs currently released by Tencent Wxapi.d.ts

Just refer to the file in your program, and if you are using Visual Studio to develop it, you can have code hints.

The following is a code example of a demo app developed with Typescript:

<reference path= "./wxapi.d.ts"/>
App ({
onlaunch:function () {
//Call API get data from local cache let
logs: any = Wx.getstoragesync (' logs ');
if (! Array.isarray (Logs)) {
logs = [];
}
(<any[]>logs). Unshift (Date.now ());
Wx.setstoragesync (' logs ', logs);
},
getuserinfo:function (CB: (param:any) => void) {let that
= this< C13/>if (this.globalData.userInfo) {
cb (THIS.GLOBALDATA.USERINFO)
} else {
//Call Login interface
Wx.login ({
success: () => {
Wx.getuserinfo ({
success: (res) => {
That.globalData.userInfo = Res.userinfo;
CB (THAT.GLOBALDATA.USERINFO);}}
);}}
,
globaldata: {
userInfo: Null
}
});

Interested friends, you can go to https://code.msdn.microsoft.com/How-to-develop-WeChat-1105555e to download the complete code sample as well as the very key micro-trust applet typescript API definition File!

More scripting examples, access to Microsoft one code sample library: Http://aka.ms/onescriptsamples More code samples, access to Microsoft one Script Sample library: Http://aka.ms/onecodesamples

The above is a small series to introduce the use of typescript to develop micro-letter procedures, hope to help everyone, if you have any questions welcome to my message, small series will promptly reply to everyone!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.