Microsoft/TypeScript

"Type X is missing the following properties from type Y" showing the wrong properties

Open

#49,347 建立於 2022年6月2日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
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

貢獻者指南