Проверка типа углового плюща: тип SafeHtml нельзя назначить типу string - PullRequest
1 голос
/ 07 октября 2019

Я получаю Ошибка машинописи после переключения на Компилятор 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>');
  }
}

Мой вопрос: как преобразовать SafeHtml и SafeUrl в строку? Это просто .toString() ОК?

Angulars 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;
}

innerHtml - это тип string, тогда как у меня есть SafeHtml.

Как воспроизвести:

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

enter image description here

1 Ответ

1 голос
/ 07 октября 2019

Кажется, это ошибка, на данный момент это ответ: https://github.com/angular/angular/issues/33028

...