Angular Ivy 类型检查:类型“SafeHtml”不可分配给类型“string”

Fel*_*lix 5 typescript angular angular-ivy

切换到Ivy 编译器后出现Typescript 错误

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

在 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>');
  }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是如何转换SafeHtmlSafeUrl字符串?就这样就.toString()OK了吗?

AngularsSafeHtml声明为:

/**
 * Marker interface for a value that's safe to use as HTML.
 *
 * @publicApi
 */
export declare interface SafeHtml extends SafeValue {
}
Run Code Online (Sandbox Code Playgroud)

以及 lib.dom.d.ts 中定义的 [innerHtml]:

interface InnerHTML {
    innerHTML: string;
}
Run Code Online (Sandbox Code Playgroud)

innerHtml类型string,而我有SafeHtml

如何重现:

git clone https://github.com/felikf/angular-repro-safe-html.git
npm i
npm run build
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述