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

Investigate: can I make foo.get('bar') a TS assertion that bar exists? #260

Open
a-type opened this issue Jul 27, 2023 · 1 comment
Open
Labels
idea I'm considering this, but no guarantees. Is it aligned and feasible?

Comments

@a-type
Copy link
Owner

a-type commented Jul 27, 2023

For:

if (foo.get("bar")) {
  x = foo.get("bar") + 1; // ts error... it can't be sure the return is still truthy
}
@a-type
Copy link
Owner Author

a-type commented Jul 27, 2023

Nah, TS won't do it with that syntax.

But maybe I could define them as readonly properties? I mean, I'm already generating types for everything, right? And there's a schema which would inform the entity at instantiation which properties to define on itself.

This wouldn't work for any type fields.

@a-type a-type added the idea I'm considering this, but no guarantees. Is it aligned and feasible? label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea I'm considering this, but no guarantees. Is it aligned and feasible?
Projects
None yet
Development

No branches or pull requests

1 participant