Skip to content

[Bug] Fix SanitizerConfig type definition #1513

@hata6502

Description

@hata6502

Describe a bug.

html-janitor supports callback pattern in order to customize the sanitizing behavior.
https://github.com/guardian/html-janitor#using-logic

But, it isn't supported as TypeScript definition.

Steps to reproduce:

Example: line 182, src/components/core.ts

    this.config.sanitizer = this.config.sanitizer || {
      p: true,
      b: true,
      a: true,
      test: (element: any) => true,
    } as SanitizerConfig;
$ yarn tsc --noEmit
src/components/core.ts:182:54 - error TS2352: Conversion of type '{ p: true; b: true; a: true; test: (element: any) => boolean; }' to type 'SanitizerConfig' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Property 'test' is incompatible with index signature.
    Type '(element: any) => boolean' is not comparable to type 'boolean | { [attr: string]: string | boolean; } | (() => any)'.
      Type '(element: any) => boolean' is not comparable to type '() => any'.

182     this.config.sanitizer = this.config.sanitizer || {
                                                         ~
183       p: true,
    ~~~~~~~~~~~~~~
... 
186       test: (element: any) => true,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187     } as SanitizerConfig;

Expected behavior:
Prevent TypeScript error even use callback in sanitizer config.

Editor.js version: 2.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions