仅具有驼峰式大小写键的对象类型

问题描述 投票:0回答:1

有没有办法编写强制对象键采用驼峰命名法的类型或接口?

type CamelCaseObject = // ... ?

const myObject: CamelCaseObject;
myObject.camelCaseKey; // Ok
myObject.not_camel_case_key; // Not ok.

或者有一个界面也可以。

interface ICamelCaseObject = {
  [key: string /* that matches camelCase */]: OtherType;
}

const myObject: ICamelCaseObject;
myObject.camelCaseKey; // Ok
myObject.not_camel_case_key; // Not ok.
typescript typescript-typings
1个回答
3
投票

因与 OpenAI 合作而被删除。我的帐户很可能会被删除,这是我的意图。

© www.soinside.com 2019 - 2024. All rights reserved.