Closed
Description
TypeScript Version: 3.4.5
Search Terms:
react default props defaultProps functional component stateless
Code
import React from "react";
interface Props {
name: string;
optional: string;
}
const Component = ({ name, optional = "default" }: Props) => (
<p>{name + " " + optional}</p>
);
const Test = () => <Component name="test" />;
Expected behavior:
According to the TypeScript 3.0 release notes, the optional
prop should not be required in Test
as it has been defined with a default using the ES2015 default initializers feature in Component
.
Actual behavior:
The following compile error is thrown:
Property 'optional' is missing in type '{ name: string; }' but required in type 'Props'.
Playground Link:
Link
It doesn't look like the playground supports TSX.
Related Issues:
#27425