Microsoft/TypeScript

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

Open

#49.347 geöffnet am 2. Juni 2022

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: Error MessagesHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide