Typescript errors when setting declaration to TRUE

后端 未结 1 1222
不思量自难忘°
不思量自难忘° 2021-01-18 18:44

I\'m trying to create typescript definitions for a Angular 2 project I\'m working on so that it can be an exportable library.

I have several services setup that ret

相关标签:
1条回答
  • 2021-01-18 19:41

    As of today, the compiler won't automatically import types for you in a declaration file.

    The best workaround for now is to manually disable your lint rules for the import, or to import the type and use an explicit type annotation so that the linter marks it as a usage.

    In other words

    // Explicit import of 'Observable' so that '.d.ts' files
    // can be generated correctly.
    import { Observable } from "node_modules/rxjs/Observable";
    
    // Explicit use of 'Observable' to satisfy your linter.
    public create(user: User): Observable {
      return this.http.post(this._apiUrls.create,
         JSON.stringify(user), {
           headers: this.apiConfig.getApiHeaders()
        });
    }
    
    0 讨论(0)
提交回复
热议问题