typescript - 如何为整个目录中的打字稿模块文件创建接口?
问题描述
我有api
目录,我想为此目录中的模块文件指定此接口。:
export interface API<
Model extends BaseModel,
Filters extends Record<string, unknown>,
Permissions extends PermissionsType<string> = PermissionsType<string>
> {
create?: (data: Model) => HttpClientResponse<Model>
destroy?: (id: Pick<Model, 'id'>) => HttpClientResponse
update?: (data: Model) => HttpClientResponse<Model>
useList?: (filters?: Filters) => ApiHookResult<PaginationData<Model>>
useItem?: (id: Pick<Model, 'id'>) => ApiHookResult<Model>
usePermissions?: () => ApiHookResult<Permissions>
}
这样api
目录中的每个文件都只能包含这些功能。我该怎么做?
解决方案
尚不完全清楚您的要求是什么,但如果您想为API
每个 api 分配接口,只需导入API
每个文件并使用implements
.
fooApi.ts:
import { API } from 'types.ts' // or wherever you declare this type
class FooApi implements API {
...
}
barApi.ts:
import { API } from 'types.ts' // or wherever you declare this type
class BarApi implements API {
...
}
推荐阅读
- javascript - 将传单屏幕截图保存为表单
- heroku - 分解后检索文件更改
- amazon-web-services - 将 cassandra-stress 连接到 AWS Keyspaces
- c++ - VS 2017跨项目链接错误在一个解决方案中
- powershell - 使用 Powershell 创建约会
- r - 使用多个对象的 ID 名称创建列
- modx-revolution - 将带有架构和 JavaScript 的自定义 HTML 输入到单个页面 modx 的问题
- vue.js - 数组中字符串的Vuejs反应式绑定
- amazon-web-services - 如何在 Appsync 中使用 OpenID Connect 验证订阅?
- javascript - 检查对象是否包含值 0 并注入 DOM