gpt4 book ai didi

angular - 当使用 filter(Boolean) 运算符时,类型 'unknown' 不可分配给类型 'string'

转载 作者:行者123 更新时间:2023-12-03 23:10:34 25 4
gpt4 key购买 nike

.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) 后运算符(operator)到管道。没有过滤器操作符,我没有看到任何错误,我是不是遗漏了什么??

最佳答案

我认为错误是指您的函数 subscribe 的参数没有任何类型

.subscribe(siteName => this.siteName = siteName);

正确的应该是:
.subscribe(siteName:string => this.siteName = siteName);

关于angular - 当使用 filter(Boolean) 运算符时,类型 'unknown' 不可分配给类型 'string',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58311760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com