Skip to content

"".isWellFormed() doesn't type-check #24238

@skybrian

Description

@skybrian

Version: Deno 1.44.2

The isWellFormed() method on strings works, but doesn't type-check.

% cat >> bug.ts
"".isWellFormed()

% deno check bug.ts 
Check [redacted]/bug.ts
error: TS2339 [ERROR]: Property 'isWellFormed' does not exist on type '""'.
"".isWellFormed()
   ~~~~~~~~~~~~
    at [redacted]/bug.ts:1:4

% deno
Deno 1.44.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> "".isWellFormed()
true
> 

Here is a workaround:

interface ExtraStringMethods {
  isWellFormed(): boolean;
}

function isWellFormed(str: string): boolean {
  return (str as unknown as ExtraStringMethods).isWellFormed();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlytypesIssues related to TypeScript types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions