1

I have a terrible data structure that is causing TypeScript to freak out.

let foo = {
    'baz':[
        [[x1, x2, x3], (a: any, b: number, c: number) => 5],
        [[x4], (a: number) => 7]],
    'bar':[
        [[], () => 0]]
}

x1, x2... are all (s: string) => number | string functions. I'm struggling to explicitly define foo's type. In Java-esque terms, it would be

Map<String, List<Tuple<List<Function<String,Any>>, Function<Any...,Integer>>>>

A list of lists, where the inner list has a list of functions and a function. As an aside, the number of elements in the list of functions will always equal the number of parameters in the anonymous function. The TypeScript compiler recommends:

 Record<string, (any[] | ((...args: any) => number))[][]>

However, when I attempt to call foo['baz'][0][0][2](myString), to call x3(myString), the compiler yells

TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used 
to index type 'any[] | ((...args: any) => number)'.   No index signature with a parameter of 
type 'number' was found on type 'any[] | ((...args: any) => number)'.

1 Answer 1

1
Record<string, [((operand: string) => (string | number))[], ((...v: any[]) => number)][]>

I found it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.