Preact: TypeScript: `render`'s first arg needs to be nullable

Created on 2 Feb 2018  路  4Comments  路  Source: preactjs/preact

In order to remove an element, I need to be able to do render(null, parentEl, elToRemove). In the typings file, render鈥檚 first argument is typed Element, which is non-nullable, precluding passing in null. This is preventing me from removing elements from a TypeScript project. The source suggests that this argument can be null, undefined, a boolean (?), a string or a number.

(I haven't gotten this far yet, but I assume that if render returns the rendered element, and I'm removing things, it an also return null, which means the function鈥檚 return type also needs to be nullable.) (Sounds like no problem on the return type.)

beginner-friendly help wanted types

All 4 comments

Rendering null will return an empty text node.

Cool, probably no problem on the return type side then. I updated the issue to reflect.

@dcporter Want to PR the nullable arg bit?

@developit Done :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasongerbes picture jasongerbes  路  3Comments

youngwind picture youngwind  路  3Comments

nopantsmonkey picture nopantsmonkey  路  3Comments

kossnocorp picture kossnocorp  路  3Comments

matuscongrady picture matuscongrady  路  3Comments