kaleidawave / ezno

A JavaScript compiler and TypeScript checker written in Rust with a focus on static analysis and runtime performance
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.3k stars 42 forks source link

Missing `Console` methods #118

Closed notramo closed 2 months ago

notramo commented 4 months ago

console.debug('hello world') is reported by ezno check as invalid, however nearly all runtimes (most browsers, Bun, Deno, Node.js) support different logging level methods (debug, info, warn, error).

https://developer.mozilla.org/en-US/docs/Web/API/console

kaleidawave commented 4 months ago

Yep there are many definitions missing. You can see the latest full.d.ts which contains definitions of things that exist in the JavaScript specification that are injected into the root environment for the type checker: https://github.com/kaleidawave/ezno/blob/cache-and-other-types/checker/definitions/full.d.ts

and there the Console interface is missing members like debug, warn etc here https://github.com/kaleidawave/ezno/blob/41433692cd463e42295a6b66e3960bbdda70c76e/checker/definitions/full.d.ts#L146-L149


In TypeScript's definition file you can find these methods here: https://github.com/microsoft/TypeScript/blob/c4de2afcc289d42b7bef3df30911e120e8bd6d39/src/lib/dom.generated.d.ts#L26604

Ezno requires more information (or at least benefits from, it still works but isn't as accurate) about internal methods than is present in the TypeScript definition .d.ts files. Using dom.generated.d.ts and others at the moment isn't ideal for that reason (also the type checker blows up above 65536 types and it doesn't support namespace things 😅). Another solution would be to could copy this declaration method across to the current full.d.ts (and make a PR).

But the best way to solve is to create a script that creates a hybrid file, that rewrites some more detailed Ezno definitions into the large definition files found in the TypeScript repository. This would automate mismatches like this with Console. I will a think about and open a separate issue for this.


Aside: I assume as you are just testing it out as at the moment the checker is unstable and not ready for real world projects. But for the future, if you find you are blocked by missing methods/properties on internal types, you can use interface merging.

interface Console {
  debug(...items: any[]);
}

console.debug(23) // should now work
notramo commented 4 months ago

I recommend adding builtin types as soon as possible. Even if it's not complete, it would help catching edge cases, and maybe help with design decisions or implementation details.

kaleidawave commented 2 months ago

I have manually added console.debug (and all other console methods) into #135.

image

Are there any specific built in types you use that you would like prioritised either because they are commonly used or use complex types? Hopefully #121 will wipe out this category of mismatch errors.