Last active
October 22, 2019 14:11
-
-
Save danielres/ce7f90a5f7521df9a582af1f54b58415 to your computer and use it in GitHub Desktop.
React + typescript + defaultProps example
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
// Adapted from: https://github.com/microsoft/TypeScript/issues/27425 | |
// This workaround should become deprecated by: https://github.com/microsoft/TypeScript/pull/29818 | |
import * as React from "react"; | |
Person.defaultProps = { telephone: "222-333-4444" }; | |
function Person({ name, telephone }: { name: string; telephone: string }) { | |
return ( | |
<div> | |
{name} {telephone} | |
</div> | |
); | |
} | |
// Works - good | |
const test = <Person name="Hulk Hogan" />; | |
// Doesn't work - missing name, good | |
const test2 = <Person />; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment