Skip to main content
例示の型名をリネーム
ソース リンク
orangecat
  • 1,011
  • 6
  • 10

アノテーションをつけない SingleTextEditorParams (仮に RawSingleTextEditorParamsUntypedSingleTextEditorParams とします) を先に作り、
SingleTextEditorParamKeyskeyof typeof RawSingleTextEditorParamsUntypedSingleTextEditorParams とするのはいかがですか。

const RawSingleTextEditorParamsUntypedSingleTextEditorParams = {
    a: ...,
    b: ...,
    c: ...,
    d: ...,
};

type SingleTextEditorParamKeys =
    keyof typeof RawSingleTextEditorParamsUntypedSingleTextEditorParams;

const SingleTextEditorParams
    : Record<SingleTextEditorParamKeys, SingleTextEditorParamList>
    = RawSingleTextEditorParamsUntypedSingleTextEditorParams;

型をつけない SingleTextEditorParams (仮に RawSingleTextEditorParams とします) を先に作り、
SingleTextEditorParamKeyskeyof typeof RawSingleTextEditorParams とするのはいかがですか。

const RawSingleTextEditorParams = {
    a: ...,
    b: ...,
    c: ...,
    d: ...,
};

type SingleTextEditorParamKeys =
    keyof typeof RawSingleTextEditorParams;

const SingleTextEditorParams
    : Record<SingleTextEditorParamKeys, SingleTextEditorParamList>
    = RawSingleTextEditorParams;

アノテーションをつけない SingleTextEditorParams (仮に UntypedSingleTextEditorParams とします) を先に作り、
SingleTextEditorParamKeyskeyof typeof UntypedSingleTextEditorParams とするのはいかがですか。

const UntypedSingleTextEditorParams = {
    a: ...,
    b: ...,
    c: ...,
    d: ...,
};

type SingleTextEditorParamKeys =
    keyof typeof UntypedSingleTextEditorParams;

const SingleTextEditorParams
    : Record<SingleTextEditorParamKeys, SingleTextEditorParamList>
    = UntypedSingleTextEditorParams;
ソース リンク
orangecat
  • 1,011
  • 6
  • 10

型をつけない SingleTextEditorParams (仮に RawSingleTextEditorParams とします) を先に作り、
SingleTextEditorParamKeyskeyof typeof RawSingleTextEditorParams とするのはいかがですか。

const RawSingleTextEditorParams = {
    a: ...,
    b: ...,
    c: ...,
    d: ...,
};

type SingleTextEditorParamKeys =
    keyof typeof RawSingleTextEditorParams;

const SingleTextEditorParams
    : Record<SingleTextEditorParamKeys, SingleTextEditorParamList>
    = RawSingleTextEditorParams;