0

I want to add types to a function which should receive the items array of strings:

type Inputs = {
  foo: string
  items: string[];
};


const myFunction = (items: string[]) => {
    //
}

The code above works but is there a way getting the types from the Inputs type? So something like:

const myFunction = (items: Inputs.items) => {
    //
}

1 Answer 1

1

Sure, but just use bracket notation instead:

type Inputs = {
  foo: string
  items: string[];
};


const myFunction = (items: Inputs['items']) => {
  //
}
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.