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

Expose internal assert globally. #5684

Closed
kitsonk opened this issue May 20, 2020 · 4 comments
Closed

Expose internal assert globally. #5684

kitsonk opened this issue May 20, 2020 · 4 comments

Comments

@kitsonk
Copy link
Contributor

kitsonk commented May 20, 2020

While it isn't a browser standard, Node.js includes an assert() globally. We heavily use assert() in the internal code, but at runtime there is no assert() available.

Exposing it as Deno.assert() would be problematic in TypeScript because of microsoft/TypeScript#37818 as it would require a type annotation all the time if you tried to destructure it and it looks like it is unlikely to ever be addressed in TypeScript because of design limitations.

We have assert() in std/testing/asserts.ts but including a testing module just to be able to do an assert() seems very heavy weight as it includes two other dependencies as well:

https://deno.land/x/std/testing/asserts.ts
  ├── https://deno.land/x/std/fmt/colors.ts
  └── https://deno.land/x/std/testing/diff.ts

So while it isn't ideal to have something in the global namespace that isn't in browsers, it is a minor variation that makes it significantly easier to write better code, especially since assert() also provides type narrowing in TypeScript now.

@nayeemrmn
Copy link
Collaborator

Node.js includes an assert() globally.

It doesn't, I think you saw the behaviour where all of the built-in modules are automatically exposed as globals in the REPL.

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 25, 2020

Grr... you are right... 😢

(╯°□°)╯︵ ┻━┻

@ry
Copy link
Member

ry commented Jun 25, 2020

I'm reluctant to add non-standard globals.

@bartlomieju
Copy link
Member

In light of #6252 (comment) this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants