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

Polymer with TypeScript

Polymer with TypeScript

PolymerでTypeScriptを使うためのあれこれ
Polymer Meetup#1

More Decks by Taketoshi Aono(青野健利 a.k.a brn)

Other Decks in Programming

Transcript

  1. Name @brn (ꫬꅿ⨳ⵃ) Occupation ؿٗٝزؒٝسؒٝآص،٥ط؎ذ؍ـؒٝآص، Company Cyberagent ،سذؙأةآؔAI Messenger Blog

    http://abcdef.gets.b6n.ch/ Twitter https://twitter.com/brn227 GitHub https://github.com/brn
  2. const { customElement, property, query, queryAll, observe } = Polymer.decorators;!

    ! const { Element } = Polymer;! ! @customElement("my-app")! export class MyApp extends Element {! constructor() {! super();! }! @property({ type: String })! private appName: string = "my-app";! }!
  3. @property({notify: true})! foo: number = 42;! ! @property({reflectToAttribute: true})! reflectFoo:

    string = 'opened';! ! @property({readOnly: true})! readOnlyBar: number;! ! @property()! bar: string = 'yes';!
  4. @property({notify: true})! foo: number = 42;! ! @observe('foo')! private _fooChanged(newValue:

    number) {! console.log(`foo is now: ${newValue}`);! }! ! @observe(['foo', 'bar'])! private _fooBarChanged(newFoo: number, newBar: string) {! console! .log(`foo is now: ${newFoo}, bar is now ${newBar}`);! }!
  5. {! "compilerOptions": {! "target": "ES6",! "emitDecoratorMetadata": true,! "experimentalDecorators": true,! "module":

    "ESNext",! "importHelpers": false,! "lib": [! "dom",! "es5",! "es2015",! "es2016",! "es2017"! ]! }! }!
  6. "scripts": {! "test": "polymer test",! "ts": "tsc -p tsconfig.json",! "watch":

    "tsc -p tsconfig.json --watch",! "serve": "polymer serve",! "debug": "run-p watch serve"! }!
  7. // a.ts! const someValue = 1;! ! // b.ts! const

    someValue = 2; ! // cannot redclared block-scope variable!
  8. // a.ts! namespace a {! const someValue = 1;! }!

    ! // b.ts! namespace b {! const someValue = 2;! }!