Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Console methods #118

Closed
notramo opened this issue Feb 16, 2024 · 3 comments
Closed

Missing Console methods #118

notramo opened this issue Feb 16, 2024 · 3 comments
Labels
bug Something isn't working definitions Invalid/missing type definition

Comments

@notramo
Copy link

notramo commented Feb 16, 2024

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
Copy link
Owner

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

interface Console {
@DoNotIncludeThis
log(msg: any): void;
}


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

@kaleidawave kaleidawave added the bug Something isn't working label Feb 16, 2024
@notramo
Copy link
Author

notramo commented Feb 17, 2024

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working definitions Invalid/missing type definition
Projects
None yet
Development

No branches or pull requests

2 participants