.ts:
siteName: string;
this.store.pipe(
select(getSiteName),
filter(Boolean),
take(1)
).subscribe(siteName => this.siteName = siteName);
错误:
Type 'unknown' is not assignable to type 'string'
在将this.siteName
运算符添加到管道之后,我遇到了filter(Boolean)
的上述错误。没有过滤器运算符,我看不到任何错误,我错过了什么吗?
答案 0 :(得分:1)
我认为错误是指您的订阅函数的参数,该参数没有任何类型
.subscribe(siteName => this.siteName = siteName);
正确的是:
.subscribe(siteName:string => this.siteName = siteName);
答案 1 :(得分:0)
发生错误是因为TypeScript不喜欢您使用Boolean
构造函数作为传递给filter
的谓词函数。如果您切换到显式谓词功能,则它会起作用,例如:
this.store.pipe(
select(getSiteName),
filter(x => Boolean(x)),
take(1)
).subscribe(siteName => this.siteName = siteName);