javascript - Typescript import from .d.ts file -


i wrote (at point) simple components angular2.

here's code far:

import {component, view} 'angular2/angular2';  export module skapp.core{   @component({     selector: 'sk-app-side-menu'    })   @view({     template: `         <p>hello</p>     `   })   export class skappsidemenu {     menuactive: boolean;      constructor(){        this.menuactive = false;     }       showmenu(){        this.menuactive = !this.menuactive;      }   } } 

of course there's no real functionality @ point. that's not point right now.

i created own build process gulp. here's relevant part of it:

gulp.task('script', ['clean'], function() {     var tsresult = tsproject.src()       .pipe(ts(tsproject));        return merge([         tsresult.dts.pipe(rename({dirname: ''}))        .pipe(concat('sk-app.d.ts'))        .pipe(gulp.dest('dist/')),        tsresult.js        .pipe(rename({dirname: ''}))        .pipe(concat('sk-app.min.js'))        .pipe(uglify())        .pipe(gulp.dest('dist/'))     ]); }); 

at end 2 files: sk-app.min.js , sk-app.d.ts

sk-app.min.js:

var __decorate=this&&this.__decorate||function(t,e,n,r){if("object"==typeof reflect&&"function"==typeof reflect.decorate)return reflect.decorate(t,e,n,r);switch(arguments.length){case 2:return t.reduceright(function(t,e){return e&&e(t)||t},e);case 3:return t.reduceright(function(t,r){return void(r&&r(e,n))},void 0);case 4:return t.reduceright(function(t,r){return r&&r(e,n,t)||t},r)}},__metadata=this&&this.__metadata||function(t,e){return"object"==typeof reflect&&"function"==typeof reflect.metadata?reflect.metadata(t,e):void 0},angular2_1=require("angular2/angular2"),skapp;!function(t){var e;!function(t){var e=function(){function t(){}return t.prototype.showmenu=function(t){},t=__decorate([angular2_1.component({selector:"sk-app"}),angular2_1.view({template:'\n        <button (click)="showmenu()">click me!</button>\n\n        <ng-content></ng-content>\n      ',directives:[angular2_1.ngclass]}),__metadata("design:paramtypes",[])],t)}();t.skapp=e}(e=t.core||(t.core={}))}(skapp=exports.skapp||(exports.skapp={})); 

sk-app.d.ts:

export declare module skapp.core {     class skapp {         showmenu(x: string): void;     } } 

now want use component within angular2 project:

import {component, view, bootstrap} 'angular2/angular2'; import {skapp} "skapp/core";  @component({     selector: 'my-app' }) @view({     template: '<sk-app></sk-app>',     directives: [skapp] }) class myappcomponent {  }  bootstrap(myappcomponent); 

but when try compile project js typescript compiler gives me message:

error ts2307: cannot find module 'skapp/core'

when change module-definition within sk-app.d.ts file to:

declare module "skapp/core" { 

it works fine. want have definition files generated gulp without having change module declaration myself.

any appreciated.

(of course aware, angular2 still in alpha state)

export module skapp.core{ think should be:

 module skapp.core {... 

since know, typescript doesn't have module level visibility modifiers


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -