Too much of "any"
See original GitHub issueDon’t you think that there are too much of “any” type used through out the definitions, or maybe I am missing something. Consider for example these definitions:
pair(fst: any, snd: any): any[];
insert(index: number, elt: any, list: any[]): any[];
assoc(prop: string, val: any, obj: any): any;
clone(value: any): any;
// there are probably more, these are just found by a quick look
While we still can have them for the cases we don’t have a strict definitions for input/output, I still believe that main point is to squeeze out as much of type safety as we can from Typescript. So don’t you think we should have a generically typed definitions as much as possible for every function? For above examples it might look like this:
pair<F, S>(fst: F, snd: S): [F, S];
insert<T>(index: number, elt: T, list: T[]): T[];
assoc<T>(prop: string, val: any, obj: T): T;
clone<T>(value: T): T;
What do you think?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Getting Too Much of Vitamins And Minerals
Dwyer says vitamin D, calcium, and folic acid are three nutrients you may get too much of, especially through supplements. Adults who regularly ......
Read more >Is it possible to take too many vitamins?
It's possible. Once the human body uses the vitamins and minerals it needs, the rest is excreted or stored. There are some supplements...
Read more >Multiple vitamin overdose Information | Mount Sinai - New York
Any ingredient in a multiple vitamin supplement can be toxic in large amounts, but the most serious risk comes from iron or calcium....
Read more >Can You Overdose on Vitamins? - Healthline
When taken in excess, some water-soluble vitamins can cause adverse effects, some of which can be dangerous. However, similarly to vitamin K, ...
Read more >Is It Possible To Take Too Many Vitamins? - Health
Taking excess vitamins may not be such a good idea. Learn what the science says about dietary supplements and get experts' advice.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree with you in general that we should try to make the type checking as strict as feasible. Your proposal for the
pair
function is fine. Theinsert
function is less obvious. The example function of Ramda fails in case of the more strict checking:Typescript can not infer type T from the definition as
string
conflicts with the list ofnumber
s. It is a bit of an awkward example as it mainly shows that you can do weird things with javascript. So I would be in favor of the more strict approach and 1) correct the examples in the test file and 2) except that there will be some clashes in user’s code where the ‘freedom’ of javascript is exploit which is in conflict with the more strict typing.To be honest, up to now I haven’t made a clear choice, but maybe now it is a good moment to do so. Any more thoughts/ideas on this issue?
@yazla I believe TS can’t express an “array of single generic type”. That’s because JS has no tuples and you can’t disallow array of mixed types by default because it will disable tuples.