htm
htm copied to clipboard
Add noNullProps option
Since TypeScript can't typecheck tagged template strings, I've been compiling my code using babel-plugin-htm and running TypeScript on the output. That works pretty well, with one big exception: omitting the props entirely passes null rather than an empty object:
function Foo(props: { required: string }) {
// ...
}
function Bar() {
return html`<${Foo} />`;
// return h(Foo, null);
}
h's type signature allows null to be used in place of any props object, which means the preceding code works fine:
export function h<P>(
type: ComponentType<P> | string,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<Attributes & P>;
This PR introduces a noNullProps option to the Babel plugin, which if set to true passes an empty object instead of null when there are no props.