【发布时间】:2021-02-02 14:46:15
【问题描述】:
如果这有点含糊,我深表歉意,因为我不是 100% 使用打字稿。有没有办法在界面中添加打字?
技术:Angular 9、Swagger 和 TypeScript。
这是错误的,但是是这样的:
export interface PasswordRequest: components["schemas"]["PasswordRequest"] {}
我不是在寻找:
export interface PasswordRequest {
email?: string | null;
oldPassword?: string | null;
}
说来话长,但基本上 swagger 正在被改造到旧应用程序中。吐出来了
export interface components { schemas: { PasswordRequest: { email?: string | null; oldPassword?: string | null; newPassword?: string | null; };
with all the needed interface under this components > schemas structure.
我试图避免翻录/重命名接口和所有导入。
【问题讨论】:
-
“键入界面”是什么意思?接口本身是一种可以应用于事物的类型。
-
我不清楚你的目标是什么。你想从
components["schemas"]["PasswordRequest"]找到的类型开始,然后调整它以创建一个新类型吗? -
@NicholasTower 说来话长,但基本上大摇大摆的东西正在被复古装进旧应用程序。它吐出'导出接口组件{模式:{密码请求:{电子邮件?:字符串|空值; oldPassword?: 字符串 |空值;新密码?:字符串 |空值; };'我试图避免翻录/重命名接口和所有导入。
-
如果您只是希望能够通过名称
PasswordRequest引用它,那么您可以使用export type PasswordRequest = components["schemas"]["PasswordRequest"]。如果这不是你的意思,那么我仍然需要更多关于你的目标的细节 -
看看打字稿中的高级类型typescriptlang.org/docs/handbook/…
标签: angular typescript swagger typescript-typings