gpt4 book ai didi

Angular Ivy 类型检查 : Type 'SafeHtml' is not assignable to type 'string'

转载 作者:行者123 更新时间:2023-12-04 04:24:04 30 4
gpt4 key购买 nike

我收到 typescript 错误 切换到 Ivy 编译器后:

[Step 4/5] src/app/app.component.html(1,26): Type 'SafeHtml' is not assignable to type 'string'.

在 Angular 类中有一个成员属性声明为 SafeHtml :

@Component({
selector: 'app',
template: `<div [innerHTML]="description"></div>`
})
export class AppComponent {
description: SafeHtml;

constructor(private sanitizer: DomSanitizer) {}

ngOnInit(): void {
this.description = this.sanitizer.sanitize(SecurityContext.HTML, '<strong>whatever comes from server</strong>');
}
}

我的问题是如何转换 SafeHtmlSafeUrl串?难道只是 .toString()好的?

Angular SafeHtml声明为:

/**
* Marker interface for a value that's safe to use as HTML.
*
* @publicApi
*/
export declare interface SafeHtml extends SafeValue {
}

而 [innerHtml] 在 lib.dom.d.ts 中定义:

interface InnerHTML {
innerHTML: string;
}
innerHtmlstring 的类型,而我有 SafeHtml .

如何重现:

git clone https://github.com/felikf/angular-repro-safe-html.git
npm i
npm run build

enter image description here

最佳答案

这似乎是一个错误,现在这是答案:https://github.com/angular/angular/issues/33028

关于Angular Ivy 类型检查 : Type 'SafeHtml' is not assignable to type 'string' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58265539/

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