TypeScript 3.0 adds supports a new type alias in the JSX
namespace called LibraryManagedAttributes
.This helper type defines a transformation on the component’s Props
type, before using to check a JSX expression targeting it; thus allowing customization like: how conflicts between provided props and inferred props are handled, how inferences are mapped, how optionality is handled, and how inferences from differing places should be combined.
Explicit types on defaultProps
The default-ed properties are inferred from the defaultProps
property type. If an explicit type annotation is added, e.g. static defaultProps: Partial<Props>;
the compiler will not be able to identify which properties have defaults (since the type of defaultProps
include all properties of Props
).
For stateless function components (SFCs) use ES2015 default initializers for SFCs:
return <div>Hello ${name.toUpperCase()}!</div>;