A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/microsoft/TypeScript/issues/18538 below:

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

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,
  };
};

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4