【发布时间】:2020-05-21 11:39:48
【问题描述】:
看起来我不知道一些 ts 特定的编译问题。
我有这些接口:
export interface CommonSearchQuery {
text: string;
category: number;
}
export type SearchBrandQuery = CommonSearchQuery & {
availability: string;
}
export type SearchLocationQuery = CommonSearchQuery & {
zip: string;
}
export type SearchQuery = SearchLocationQuery | SearchBrandQuery;
还有我的用法
export const fetchBrands = (params: SearchQuery, type: RequestType): Promise<any> => {
console.log(params.availability);
}
我收到了这个错误
TS2339: Property 'availability' does not exist on type 'SearchQuery'.
Property 'availability' does not exist on type 'SearchLocationQuery'.
我的 ts 配置
{
"compileOnSave": false,
"compilerOptions": {
"incremental": true,
"jsx": "react",
"lib": ["es6", "dom", "ES2017"],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": false,
"noImplicitThis": true,
"strictNullChecks": true,
"declaration": true,
"baseUrl": ".",
"esModuleInterop": true,
"outDir": "dist"
},
"exclude": [
"./dist/*",
"./node_modules/*",
"./stories/*"
]
}
提前致谢
【问题讨论】:
-
只有
SearchBrandQuery有空,你的意思是->export type SearchQuery = SearchLocationQuery & SearchBrandQuery;代替吗?
标签: typescript types