Skip to content

Allow instantion expression with empty arguments #57510

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

Open
6 tasks done
rotu opened this issue Feb 23, 2024 · 2 comments
Open
6 tasks done

Allow instantion expression with empty arguments #57510

rotu opened this issue Feb 23, 2024 · 2 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@rotu
Copy link

rotu commented Feb 23, 2024

πŸ” Search Terms

instantiation expression, empty, type arguments

βœ… Viability Checklist

⭐ Suggestion

I would like to be able to instantiate a generic function type with an empty type arguments list.

It would be nice to allow this for generic types, but it's not as necessary, since a generic type is always instantiated in a type context, even if no type arguments list is given. A generic function type needs to be specifically instantiated.

πŸ“ƒ Motivating Example

Here is a generic function where a type parameter has a default. I can get use an instantiation expression to specialize it to a non-generic function.

declare function find1<T, S extends T=T>(Ar:T[], predicate:(t:T)=>t is S): S | undefined;
type Find1Object = typeof find1<object>;

Here is a generic function with only one type parameter. I cannot use an instantiation expression with the default for S:

declare function find2<S extends object = object>(Ar:object[], predicate:(t:object)=>t is S) : S | undefined;
type Find2 = typeof find2<>; // <- this is a syntax error "Type argument list cannot be empty"

πŸ’» Use Cases

  1. What do you want to use this for?
  2. What shortcomings exist with current approaches?
  3. What workarounds are you using in the meantime?
    • Declare an unused "dummy" type parameter so there's always a non-defaulted type argument.

Originally mentioned here: #57463 (comment)

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 28, 2024
@RyanCavanaugh
Copy link
Member

@ahejlsberg any thoughts? Seems straightforward enough?

@jcalz
Copy link
Contributor

jcalz commented Nov 18, 2024

Can we get this for calling the function directly also? That is: just support empty type argument lists for generic functions, if all of the type parameters have defaults. It would be weird for (f<>)() to work but for f<>() not to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants