Created
May 9, 2017 10:48
-
-
Save patrick91/8e6f28bcaa7e2c8dbf8676c67ddb9426 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import styled from 'styled-components'; | |
import { ComponentClass, StatelessComponent } from 'react'; | |
export type Component<P> = ComponentClass<P> | StatelessComponent<P>; | |
interface FooProps { | |
message: string, | |
primary: boolean, | |
}; | |
interface NewComponentProps { | |
message: string, | |
}; | |
const getTestComponent = ({ Foo }: { Foo: Component<FooProps> }): Component<NewComponentProps> => { | |
return class NewComponent extends React.Component<NewComponentProps, void> { | |
render() { | |
return ( | |
<Foo message={this.props.message} primary /> | |
) | |
} | |
} | |
} | |
// Autocompletes as expected and works | |
const NormalTestComponent = getTestComponent({ | |
Foo: (props) => ( | |
<div>{props.message}</div> | |
), | |
}) | |
// Styled Components does not autocomplete on interpolation and doesnt work | |
const StyledTestComponent = getTestComponent({ | |
Foo: styled.div` | |
background: ${(props: NewComponentProps) => props.primary ? 'red' : 'purple'}; | |
`, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment