-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Type checked getters and setters #125
Comments
Hello @DouglasLivingstone, thanks for the follow up. Let me document myself more about how TypeScript type checking works so I can see whether something might be improved for the library without too much pain. |
On a slightly related matter, may I ask you if you know cursors libraries working with a type checking solution? |
No, I've not seen a dedicated library for it. Informally in my own code I have structures which look like this:
which is used a bit like a cursor, but no, not really. Currently I'm considering whether to just remove the abstraction, so eg,
or replace it with a more general library, something that might let me write,
but not sure yet. The last example is short, but I don't see how to type-check that the form's value property matches the type of the field without ending up writing more code than it started off with. |
Hello @DouglasLivingstone. I am afraid I haven't found a fresh solution to your problem here. Any luck on your side? |
Following on from this post, I'm looking for a way to use cursors with TypeScript type checking. I'm not sure it fits within the scope of this project, but this is what I have in mind.
Here's a class with two properties of different types:
Accessing the .length property on a number is invalid, so the idea is to get an early error message at compile time, rather than only at runtime, by providing type hints.
One way of making cursors work with TypeScript is using type inference with functions to read properties instead of string keys, but doing it like this means properties are read-only. A simple workaround is to pass a writer as well as a reader in, but I'm interested in ways to avoid that without horrible hacks (for example by generating the code for the setter from the getter, and using the getter only for type information).
The text was updated successfully, but these errors were encountered: