Type constrain after type inference, example usage and benefit discussed #1418
Xyncgas
started this conversation in
Type System
Replies: 1 comment
-
I can see sometimes it can be redundant if everything is already inferred |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
A function's parameters can be inferred of their types. Another function's parameters may be inferred of their types in a different way unless you specify their types to exactly be the inferred types of the first function in the programes.
Now it's possible adding convenience by constraining types to the inferred types. You can use generic today, though intellisense is not helping you inside the function body if the type you are using has non native types (classes) in its signature.
A better function would be constraining its parameters types to the inferred types of another function
Yes you can constrain arg1 to anything having a method called .eat() but you had to write it down and what if there's another dozens of methods you needed
If there is a heavy amount of signatures to type out in the project the technique can greatly reduce the noises and let programmer focus on enjoying benefits provided by the type inference system
Beta Was this translation helpful? Give feedback.
All reactions