本文介绍了在Angular 2应用中使用接口和OpaqueToken时出现打字稿警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在遵循文档 ,然后使用 ng-cli .

I have been following the documentation here and use ng-cli.

我创建了以下配置文件( app-config.ts ):

I created the following configuration file (app-config.ts):

import { OpaqueToken } from '@angular/core';

export interface AppConfig {
  supportTelephoneNumber: string;
}

export let APP_CONFIG_t = new OpaqueToken('app.config');

export const APP_CONFIG: AppConfig = {
  supportTelephoneNumber: '1111 111 1111'
};

以及我的 app.module.ts 文件中:

...
@NgModule({
  declarations: [
    UkCurrencyPipe,
    AppComponent,
    HomeComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule.forRoot(ROUTES, { useHash: true }),
    MaterialModule.forRoot()
  ],
  providers: [
    { provide: APP_CONFIG_t, useValue: APP_CONFIG },
    ...

我在 app.component.ts 文件中使用此配置,如下所示:

I use this configuration in my app.component.ts file like this:

import { Component, Inject } from '@angular/core';
import { APP_CONFIG_t, AppConfig } from './app-config';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less']
})
export class AppComponent {
  constructor(@Inject(APP_CONFIG_t) public config: AppConfig) {

  callSupport(): void {
    window.location.href = 'tel:+' + this.config.supportTelephoneNumber;
  }
}

当我使用 ng serve 服务我的应用程序时,一切似乎都可以正常运行,但是我在运行 ng服务器的控制台中确实看到了这些警告:

When I serve my app using ng serve everything seems to work fine but I do see these warnings in the console from where I run ng server:

./src/app/app.component.ts中的警告
40:195在'./app-config'中找不到导出'AppConfig'

WARNING in ./src/app/app.component.ts
40:195 export 'AppConfig' was not found in './app-config'

有人知道这些警告的含义吗,我是否应该担心它们?

Does anyone know what these warnings mean and whether or not I should worry about them?

我的版本

  • OS:Mac OS X El Capitan v10.11.6
  • ng-cli:v1.0.0-beta.16
  • 角度:v2.0.1
  • 打字稿:v2.0.2

推荐答案

根据评论关于问题 https://github.com/angular/angular-cli/issues/2034

表示如果我有一个具有多个导出功能的文件-我在构建中得到警告(在'../file'中找不到导出'MyInterface1')

meaning if i had one file with multiple exports - i got warnings in build (export 'MyInterface1' was not found in '../file')

file.ts

export interface MyInterface1 {}
export interface MyInterface2 {}

file1.ts

export interface MyInterface1 {}
export interface MyInterface2 {}

这篇关于在Angular 2应用中使用接口和OpaqueToken时出现打字稿警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:39