Public 属性 X of exported class 具有或正在使用来自外部模块“/rxjs/internal/Observable”的名称 'Observable' 但无法命名
Public property X of exported class has or is using name 'Observable' from external module "/rxjs/internal/Observable" but cannot be named
我已经实现了在组件之间共享数据的服务:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
private dataSource = new BehaviorSubject(Object);
public currentData = this.dataSource.asObservable();
constructor() {}
changeData(data) {
this.dataSource.next(data);
}
}
一切正常,直到我尝试构建项目。然后我得到了这个错误:
error TS4029: Public property 'currentData' of exported class has or is
using name 'Observable' from external module
"/rxjs/internal/Observable"
but cannot be named.
经过一些调查,我意识到我正在使用 属性,它指的是 Observable,但找不到它。要修复它,我需要简单地添加缺少的 Observable
导入并输入 currentData
变量:
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
private dataSource = new BehaviorSubject(Object);
public currentData: Observable<Object> = this.dataSource.asObservable();
constructor() {}
changeData(data) {
this.dataSource.next(data);
}
}
然而,只有当我将项目转换为库时才会出现错误。
在我的例子中,错误是 angular 中的 Ionify 库,下面的代码导致 angular 库编译错误:
import icSettings from '@iconify/icons-ic/twotone-settings';
...
@Component({
....
})
export class ConfigPanelToggleComponent implements OnInit {
icSettings = icSettings; // This causes error
}
解决方案是使用任何类型,因为 @iconify 库不导出所需的类型。
import icSettings from '@iconify/icons-ic/twotone-settings';
...
@Component({
....
})
export class ConfigPanelToggleComponent implements OnInit {
icSettings: any = icSettings; // No error
}
我已经实现了在组件之间共享数据的服务:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
private dataSource = new BehaviorSubject(Object);
public currentData = this.dataSource.asObservable();
constructor() {}
changeData(data) {
this.dataSource.next(data);
}
}
一切正常,直到我尝试构建项目。然后我得到了这个错误:
error TS4029: Public property 'currentData' of exported class has or is using name 'Observable' from external module "/rxjs/internal/Observable" but cannot be named.
经过一些调查,我意识到我正在使用 属性,它指的是 Observable,但找不到它。要修复它,我需要简单地添加缺少的 Observable
导入并输入 currentData
变量:
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
private dataSource = new BehaviorSubject(Object);
public currentData: Observable<Object> = this.dataSource.asObservable();
constructor() {}
changeData(data) {
this.dataSource.next(data);
}
}
然而,只有当我将项目转换为库时才会出现错误。
在我的例子中,错误是 angular 中的 Ionify 库,下面的代码导致 angular 库编译错误:
import icSettings from '@iconify/icons-ic/twotone-settings';
...
@Component({
....
})
export class ConfigPanelToggleComponent implements OnInit {
icSettings = icSettings; // This causes error
}
解决方案是使用任何类型,因为 @iconify 库不导出所需的类型。
import icSettings from '@iconify/icons-ic/twotone-settings';
...
@Component({
....
})
export class ConfigPanelToggleComponent implements OnInit {
icSettings: any = icSettings; // No error
}