Proposal: Variadic Kinds -- Give specific types to variadic functions
Problem
Variadic Kinds Give Specific Types to Variadic Functions This proposal lets Typescript give types to higher-order functions that take a variable number of parameters. Functions like this include `concat`, `apply`, `curry`, `compose` and almost any decorator that wraps a function. In Javascript, these higher-order functions are expected to accept variadic functionsas arguments. With the ES2015 and ES2017 standards, this use will become even more common as programmers start using spread arguments and rest parameters for both arrays and objects. This proposal addresses these use cases with a single, very general typing strategy based on higher-order kinds. This proposal would completely or partially address several issues, including: 1. #5331 -- Tuples as types for rest ...arguments 2. #4130 -- Compiler incorrectly reports parameter/call target signature mismatch when using the spread operator 3. #4988 -- Tuples should be clonable with Array.prototype.slice() 4. #1773 -- Variadic generics? 5. #3870 -- Rest types in generics for intersection types. 6. #212 -- bind, call and apply are untyped (requires #3694's this-function types). 7. #1024 -- Typed ...rest parameters with generics I'll be updating this proposal on my fork of the Typescript-Handbook: sandersn/TypeScript-Handbook@76f5a75868de3fb1ad4dbed5db437a8ab61a2698 I have an in-progress implementation at sandersn/TypeScript@f3c327aef22f6251532309ba046874133c32f4c7 which currently has the simple parts of the proposal impleme
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Proposal: Variadic Kinds -- Give specific types to variadic functions
+1, this is really useful for functional programming in TypeScript! How would this work with optional or rest arguments? More concrete, can the `compose` function be used on functions with rest arguments or optional arguments?
Trust Score
7 verifications
- 1
+1, this is really useful for functional programming in TypeScript! How would th
+1, this is really useful for functional programming in TypeScript! How would this work with optional or rest arguments? More concrete, can the `compose` function be used on functions with rest arguments or optional arguments?
Validation
Resolved in microsoft/TypeScript GitHub issue #5453. Community reactions: 35 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep