question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Too much of "any"

See original GitHub issue

Don’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:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
donnutcommented, Mar 8, 2016

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. The insert function is less obvious. The example function of Ramda fails in case of the more strict checking:

R.insert(2, 'x', [1,2,3,4]); //=> [1,2,'x',3,4]

Typescript can not infer type T from the definition as string conflicts with the list of numbers. 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?

1reaction
ivan-kleshnincommented, Jul 18, 2016

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found