Microsoft/TypeScript
在 GitHub 查看"Type X is missing the following properties from type Y" showing the wrong properties
Open
#49,347 创建于 2022年6月2日
BugDomain: Error MessagesHelp Wanted
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
Bug Report
🔎 Search Terms
- "is missing the following properties"
- missing properties message
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
⏯ Playground Link
Playground link with relevant code
💻 Code
export type Props<Row, Cols> =
& PaginationProps
& { data: Array<Row>; columns: DataGridColumns<Row, Cols>; };
type PaginationProps =
| { paginate?: false }
| {
paginate: true;
currentPage: number;
totalPages: number;
onChangePage: (page: number) => Promise<unknown>;
};
export type DataGridColumns<Row, Cols> = {
[K in keyof Cols]: Column<Row, Cols, K>;
};
export type Column<Row, Cols, Key extends keyof Cols> = {
label: string;
getValue: (row: Row) => Cols[Key];
getDisplayValue?: (row: Row) => string;
renderView?: (value: Cols[Key], row: Row) => string;
renderEdit?: (opts: {
row: Row;
value: Cols[Key];
isEnabled: boolean;
setValue: (value: Cols[Key]) => void;
setValues: (props: Partial<Cols>) => void;
}) => string;
alignment?: "left" | "center" | "right";
};
type Person = { lastName: string, firstName: string, birthdate: Date };
const props: Props<Person, { fullName: string, age: number }> = {
data: []
};
🙁 Actual behavior
The error message for props is not that it's missing the required columns property but that it's missing properties from PaginationProps, which in actuality allows for the properties to be omitted.
Type '{ data: never[]; }' is not assignable to type 'Props<Person, { fullName: string; age: number; }>'.
Type '{ data: never[]; }' is not assignable to type '{ paginate: true; currentPage: number; totalPages: number; onChangePage: (page: number) => Promise<unknown>; } & { data: Person[]; columns: DataGridColumns<Person, { fullName: string; age: number; }>; }'.
Type '{ data: never[]; }' is missing the following properties from type '{ paginate: true; currentPage: number; totalPages: number; onChangePage: (page: number) => Promise<unknown>; }': paginate, currentPage, totalPages, onChangePage
🙂 Expected behavior
I should be told that I'm missing the columns property. In actuality this type is even more complex, and the bad error message makes it difficult to know which properties are actually missing without looking at the source code. Something like this would be more correct:
Type '{ data: never[]; }' is imissing the following properties from type 'Props': columns