Closed Ph0enixKM closed 1 month ago
what about adding explicit Any
type and every time you need to put a generic type anywhere you just use Any
? (including arrays)
Yeah.. I've been thinking about this... if this is a good idea to introduce such type. TypeScript has done it because JS enforced it. Aaaand... in any real project you're advised not to use it. So this was a proposition that would not lead people to bad patterns. If you want to use Any
type - then just don't specify any type. What do you think?
How about we add generics instead.
fn foo<T>(array: [T]) {
}
I'd start with the generic array, as it is simpler to implement and to use. Also we don't have to limit it to parameters, it might be useful as a return type, too.
Then, later on, we can extend this syntax to also allow named generics such as fn first<T>(arr: [T]): T
. Except I'd also look for a better syntax that won't require defining them before using, like fn first(arr: ['T]): 'T
.
I'd start with the generic array, as it is simpler to implement and to use. Also we don't have to limit it to parameters, it might be useful as a return type, too.
Then, later on, we can extend this syntax to also allow named generics such as
fn first<T>(arr: [T]): T
. Except I'd also look for a better syntax that won't require defining them before using, likefn first(arr: ['T]): 'T
.
I like this 'T
syntax
I love that idea of 'T
syntax @mks-h ! Great job!
Is your feature request related to a problem? Please describe. The problem is that sometimes a person might want to match any Array type when declaring a function parameter.
Describe the solution you'd like
[]
syntax in Types[]
type only in function parameter types.Describe alternatives you've considered I've considered function overloading but it seems to be an overkill.
Additional context This way we can more precisely specify the context and use of functions.