Skip to content

Instantly share code, notes, and snippets.

@danielres
Last active October 22, 2019 14:11
Show Gist options
  • Save danielres/ce7f90a5f7521df9a582af1f54b58415 to your computer and use it in GitHub Desktop.
Save danielres/ce7f90a5f7521df9a582af1f54b58415 to your computer and use it in GitHub Desktop.
React + typescript + defaultProps example
// 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