Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Typescript with NodeJS

Typescript with NodeJS

Typescript is a superset of Javascript that compiles to plain JS. I will be discussing some Typescript basics and how Node developers can make use of what Typescript has to offer.

Related code available here: https://github.com/metaware/typescript-shopping-cart

Jasdeep Singh

October 11, 2016
Tweet

More Decks by Jasdeep Singh

Other Decks in Programming

Transcript

  1. )PXUPHFUTUBSUFE $ npm install -g typescript $ vim app.ts //

    write typescript code $ tsc app.ts $ node app.js
  2. let size: number = 3; let isManagingPartner: boolean = true;

    let name: string = "Harvey Specter"; let friends: Array<string> = ['Mike Ross', 'Jessica Pearson', 'Louis Litt’]; size = 'Rachel Zane'; // Type 'string' is not assignable to type 'number'. #BTJD5ZQFT
  3. let foo: any foo = 1; foo = 'one'; foo

    = [1] 4QFDJBM5ZQFABOZABMMPXTBOZWBMVFT
  4. let foo = 3; foo = 'three'; // Type 'string'

    is not assignable to type 'number'. 5ZQF*OGFSFODF
  5. function authenticate(username: string, password: string): boolean { // some authentication

    logic return true; } function authenticate(user: { username: string, password: string }): boolean { // some authentication logic return true; } GVODUJPOQBSBNFUFSTSFUVSOWBMVFT
  6. { firstName: 'John', lastName: 'Doe', // age is optional fullName:

    function() { return this.firstName + ' ' + this.lastName } address: { city: 'Toronto', postalCode: 'M5M M5M' } } *OUFSGBDFT
  7. interface User { firstName: string, lastName: string, age?: number, fullName():

    string, address: { city: string, postalCode: string } } *OUFSGBDFT