denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.4k stars 5.18k forks source link

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

Open skybrian opened 2 weeks ago

skybrian commented 2 weeks ago

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();
}
satyarohith commented 2 weeks ago

This is working as expected similar to tsc:

➜  ~ cat -p a.ts
"".isWellFormed();
➜  ~ deno check a.ts
Check file:///Users/sr/a.ts
error: TS2339 [ERROR]: Property 'isWellFormed' does not exist on type '""'.
"".isWellFormed();
   ~~~~~~~~~~~~
    at file:///Users/sr/a.ts:1:4
➜  ~ tsc a.ts
a.ts:1:4 - error TS2339: Property 'isWellFormed' does not exist on type '""'.

1 "".isWellFormed();
     ~~~~~~~~~~~~

Found 1 error in a.ts:1
petamoriken commented 2 weeks ago

I'll update types at tsc side

ref: https://github.com/microsoft/TypeScript/pull/58573

petamoriken commented 2 weeks ago

@satyarohith This issue is working in progress, not working as designed