-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterRelates to the JSX parser and emitter
Milestone
Description
TypeScript Version: 3.3.0-dev.20181208
Search Terms:
- HOC
- react
- higher order component
Code
import * as React from 'react';
export interface HOCProps {
foo: number;
}
/** Remove props, that have been prefilled by the HOC */
type WithoutPrefilled<T extends HOCProps> = Pick<T, Exclude<keyof T, 'foo'>>;
function withFoo<P extends HOCProps>(WrappedComponent: React.ComponentType<P>) {
return class SomeHOC extends React.Component<WithoutPrefilled<P>> {
public render(): JSX.Element {
return <WrappedComponent {...this.props} foo={0} />;
}
};
}Expected behavior:
No error, like with every version below 3.2.0.
Actual behavior:
Throws an error highlighting the WrappedComponent in the render method.
[ts]
Type 'Readonly<{ children?: ReactNode; }> & Readonly<Pick<P, Exclude<keyof P, "foo">>> & { foo: number; }' is not assignable to type 'IntrinsicAttributes & P & { children?: ReactNode; }'.
Type 'Readonly<{ children?: ReactNode; }> & Readonly<Pick<P, Exclude<keyof P, "foo">>> & { foo: number; }' is not assignable to type 'P'. [2322]
Additional Information
This is pretty much the same sample example used in #28720, but with the difference, that the props of the returned component differ from the generic.
Basically the HOC prefills the foo property for the WrappedComponent. Since the spreaded props are overriden by foo, I don’t want foo to be a valid property for the HOC. This does not seem to be possible anymore.
Playground Link:
Related Issues:
#28720
nurpax, arutkowski00, que-etc, pansinm, rexk and 75 more
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterRelates to the JSX parser and emitter