gpt4 book ai didi

javascript - 如何扩展 typescript 接口(interface)?

转载 作者:行者123 更新时间:2023-12-01 01:35:37 28 4
gpt4 key购买 nike

因此,我有一个请求接口(interface),该请求的 header 来自 IoperationParam ,主体与 patentList 相同,它是对象数组,但它会抛出错误 PatientId 无法分配给IGetSpecialtyQuestionsParam 知道这里需要纠正什么吗?

main.interface.ts

    export interface IGetSpecialtyQuestionsParam extends IOperationParam {
patientList: (ISpecialtyQuestionsEntity)[];
}
export interface ISpecialtyQuestionsEntity {
/**
* <H3>This maps to ESL patientId<H3>
*/
patientId: string;
/**
* 1982-01-10
*/
dateOfBirth: string;
/**
* Female
*/
gender: "Male"|"Female";
/**
* We can default this;
* Specialty HBS
*/

sourceSystem: string;


rxInfo?: (RxInfoEntity)[] | null;
}

export interface IOperationParam {
appName: string;
appId: string
}

最佳答案

您似乎混淆了类和接口(interface)。接口(interface)仅定义数据的形状,而不是默认值。

您的界面应该是:

export interface IOperationParam {
appName: string;
appId: string
}

export interface IGetSpecialtyQuestionsParam extends IOperationParam {
patientList: ISpecialtyQuestionsEntity[];
}

export interface ISpecialtyQuestionsEntity {
patientId: string;
dateOfBirth: string;
gender: string;
sourceSystem: string;
rxInfo?: RxInfoEntity[];
}

您所说的错误:“...patentId 无法分配给 IGetSpecialtyQuestionsParam...”

之所以发生,是因为 IGetSpecialtyQuestionsParam 扩展了 IOperationParam,它没有属性:patentId

因此,您需要在 IOperationParam 接口(interface)中包含 patentId,或者将其添加为 IGetSpecialtyQuestionsParam 接口(interface)的一部分,或者扩展一个通用界面...最适合您的应用程序的界面。

关于javascript - 如何扩展 typescript 接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52857754/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com