1

I've got class which have static property params. Via some under the hood magic(outside of typescript) each instance of this class will have access to this.params which will be more or less copy of static property. Static params is typed as Record<string, ParamDef> where ParamDef can have few different shapes. That way I have help with adding new properties under static params.

this.params is typed as typeof Class.params When I want to access this.params.a.value I get type as string | number. Is it possible to get here exact type (string) while keeping static property typed?

type ParamDef = {
  type: "Text",
  value: string
} | {
  type: "Number",
  value: number
}

class Test {
  params!: typeof Test.params;

  constructor() {
    this.params.a.value; // string | number, expected string
  }
  static params: Record<string, ParamDef> = {
    a: {
      type: "Text",
      value: "someText"
    },
    b: {
      type: "Number",
      value: 3
    }
  }
}

Playground link

Godric
  • 769
  • 7
  • 18

0 Answers0