1

Given this function

function Func(token: string, deps: string[], resolveFn: (...args: any[]) => any) {
    // Stuff
}

My goal is for the resolveFn's arguments to match the dependencies.

Example this would be valid:
Func('test', ['arg1', 'arg2'], (arg1: any, arg2: any) => {})

This would not be valid:
Func('test', ['arg1', 'arg2'], (hello: any, world: any) => {})

This one is maybe more difficult but should also not be valid:
Func('test', ['arg1', 'arg2'], (arg2: any, arg1: any) => {})

Is this feasable?
Thank you

Han0003
  • 35
  • 3
  • 2
    I think this is not possible. Parameter names can not really be observed by the type system. Given a function type, the implementer can still choose any name they want. There is no way to enforce a specific one to be used. – Tobias S. Oct 21 '22 at 07:39
  • Yeah, parameter names are unobservable in TS so this is not possible. See answers to linked questions for more info. Good luck! – jcalz Oct 21 '22 at 13:48

0 Answers0