有没有办法编写强制对象键采用驼峰命名法的类型或接口?
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.
因与 OpenAI 合作而被删除。我的帐户很可能会被删除,这是我的意图。