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

Can assign incompatible measures if they have some dimensions in common, #152

Closed
niklashallenfur opened this issue Feb 29, 2020 · 5 comments · Fixed by #189
Closed

Can assign incompatible measures if they have some dimensions in common, #152

niklashallenfur opened this issue Feb 29, 2020 · 5 comments · Fixed by #189

Comments

@niklashallenfur
Copy link

The following, taken from the documentation

const error: Velocity = length.times(time);
// ERROR: A measure of m*s isn't assignable to a measure of m/s.

Gives a compile-time error.

But removing the times operation, making it just

const error: Velocity = length

Does not give a compile-time error, although the measures are clearly incompatible
Am I missing something? I have strict turned on in my tsconfig file.

Thanks otherwise for a fantastic library

@jscheiny
Copy link
Owner

Hey, thanks for bringing this to my attention! This actually exposes a pretty fundamental issue with the library that's gonna be pretty difficult to fix since typescript is structurally typed. I definitely should've thought of this sooner. This is going to take a while to resolve but my intuition right now is that we will need to make more stringent restrictions on custom dimensions that users can create in the library.

@jscheiny
Copy link
Owner

Actually this might be doable now. I had assumed that exact types would require a language update but it seems they are possible now! Will work on integrating this clever bit of type hackery into the code soon:

microsoft/TypeScript#12936 (comment)

@cloudify
Copy link

hello @jscheiny , thanks for this wonderful library - I think I just found another case where the library allows mixing units:

const a = length.times(time);
const b = length.plus(a); // <- this should not be allowed

I'm happy to help.

@phpcoder2022
Copy link

Hello. I joyed that you created so library and want help solve the problem. May be this trick help you.

@phpcoder2022
Copy link

I deleted odd hack from my solution.

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