I want to use TypeScript by pulling out the mold inside the associative array.

Asked 1 years ago, Updated 1 years ago, 477 views

Please tell me how to pull the hierarchy inside the associative array.

type Outside={
  key: {
    a: number;
    b:string;
  }
}

// I want to create an inside type from an outside type key (the outside type must not be changed)
// typeInside=typeofOutside.key // 'Outside' refers only to the type, but it is used as a value here. ts(2693)

const v —Inside=getOutsideValue().key;

javascript typescript

2022-12-09 10:00

1 Answers

You can access elements of type with [].The feature appears to be called Indexed Access Types.

type Inside=Outside ["key"];


2022-12-09 14:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.