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

Prefer {} type to any type #179

Closed
OliverJAsh opened this issue Jul 27, 2017 · 1 comment
Closed

Prefer {} type to any type #179

OliverJAsh opened this issue Jul 27, 2017 · 1 comment

Comments

@OliverJAsh
Copy link
Collaborator

any disables type checking, so any usage of an any expression will be unsafe. For example:

task.tryCatch(() => Promise.resolve(1), error => {
  // unsafe!
  return error.foo.bar
})

For this reason it is preferable to use the empty object type {}.

For more information on the differences between any and {}, and the how they are often misunderstood, see microsoft/TypeScript#9999 (comment).

Would you be happy for us to change some instances of any to {}? For example, in the onrejected function parameter of task.tryCatch:.

This would mean the above example would error unless the user widens the type (e.g. using user-defined type guards):

task.tryCatch(() => Promise.resolve(1), error => {
  // compile error
  return error.foo.bar
})
@gcanti
Copy link
Owner

gcanti commented Jul 27, 2017

LGTM

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

No branches or pull requests

2 participants