Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
apoco opened this issue Jun 2, 2022 · 1 comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@apoco
Copy link

apoco commented Jun 2, 2022

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

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jun 2, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 2, 2022
@RyanCavanaugh
Copy link
Member

Shorter

export type Props = ({ a?: false } | { a: true }) & { b: string, c: string };

const props: Props = ({
  b: "",
});

We should complain about c, but instead complain about a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants