Skip to content

For object type C, type parameter T and mapped type { [K in keyof T & C]: any }, keyof C isn't assignable to K #18538

Closed

Description

TypeScript Version: 2.5.2

Code

export interface ConfirmationComponentProps {
  title?: string,
}
function propTypes<OProps extends {}>() : {[K in keyof (OProps & ConfirmationComponentProps)]?: any } {
  return {
    title: null,
  };
};

Expected behavior:

Compile with no errors.

Actual behavior:

Fails with: { title: null }is not assignable to {[K in keyof (OProps & ConfirmationComponentProps)]?: any }`

The problem disappears if I remove the intersection type & and just use ConfirmationComponentProps; or if I replace OProps with a concrete type like:

function propTypes<OProps extends {}>() : {[K in keyof {x: number} & ConfirmationComponentProps]?: any } {
  return {
    title: null,
  };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions