Skip to content

Conversation

jakelazaroff
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant