Created
November 29, 2017 01:20
-
-
Save rjdestigter/55e6fbcd17b7e9b421e9f6e13f675a0b to your computer and use it in GitHub Desktop.
TypeScript React classes with generics throw Type '{}' is not assignable to type 'R'.
This file contains 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
// Libs | |
import * as React from 'react' | |
// Types | |
interface Bar { | |
id: number | |
} | |
interface Party<R extends Bar> { | |
attr: keyof R | |
desc: string | |
} | |
interface Props<R extends Bar> { | |
property: Party<R> | |
} | |
// Exports | |
class Test<R extends Bar> extends React.Component<Props<R>> { | |
public props: Props<R> | |
public render() { | |
return null | |
} | |
} | |
export default class ImplementTest<R extends Bar> extends React.Component<Props<R>> { | |
public props: Props<R> | |
public render() { | |
return ( | |
<Test property={this.props.property} /> | |
) | |
} | |
} |
Author
rjdestigter
commented
Nov 29, 2017
TypScript 2.6.1
"react": "^16.1.1",
"@types/react": "^16.0.25",```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment