# Introducing typed inputs in my first custom node ever

**URL:** https://discourse.nodered.org/t/introducing-typed-inputs-in-my-first-custom-node-ever/21658
**Category:** Developing Nodes
**Created:** [13 February 2020 15:24 UTC](https://discourse.nodered.org/t/introducing-typed-inputs-in-my-first-custom-node-ever/21658 "2020-02-13T15:24:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [13 February 2020 15:24 UTC](https://discourse.nodered.org/t/introducing-typed-inputs-in-my-first-custom-node-ever/21658/1 "2020-02-13T15:24:59Z")

</div>

Hi folks,

A couple of years ago I developed my first custom node ([node-red-contrib-msg-resend](https://github.com/bartbutenaers/node-red-contrib-msg-resend)), which a couple of numeric inputs on the config screen:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/30484464e40ed00c4991b7ae0d979242b61a9a01.png)

Both numeric values can be set dynamically via the input message (`msg.resend_interval` and `msg.resend_max_count`). This means that the config screen input contains the _default values_ _ **AND** _ these values can dynamically be overwritten via the input message.

Now I would like to allow the user to choose which msg field he wants to use (e.g. `msg.payload.interval`), instead of forcing him to use the `msg.resend_xxxx` fields.

This means I have to use typed inputs like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3fb10378cec9dd4c3afa6257fd412c6844e0a83d.png)

But then the interval is specified on the config screen _ **OR** _ in the input message.

So that would break existing flows...  
Anybody has an idea how I can accomplish this?

Thanks !!  
Bart

---

<div class="post-metadata">

### Author: ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)
#### Post date: [14 February 2020 00:14 UTC](https://discourse.nodered.org/t/introducing-typed-inputs-in-my-first-custom-node-ever/21658/2 "2020-02-14T00:14:24Z")

</div>

Is it just a matter of sequencing the priorities? - use `msg.` if set; if not, use `msg.resend_interval` if present; if not, use number.

Assuming you have an input along the lines of:

```auto
    <div class="form-row">
        <label for="node-input-interval"><i class="fa fa-file-text-o"></i> Interval</label>
        <input type="text" id="node-input-interval" style="width:70%">
        <input type="hidden" id="node-input-intervalType">
    </div>

```

Then the logic would be something like:

```auto
    if (intervalType === 'msg') {
        await RED.util.evaluateNodeProperty(...
    } else if (msg.hasOwnProperty('resend_interval') {
        ...overridden from msg
    } else if (intervalType === 'number') {
        ...use number entered
    } else {
        ...confused now
    }

```

For this to work for existing code, I expect you would have to default `intervalType` to 'number'.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [14 February 2020 16:57 UTC](https://discourse.nodered.org/t/introducing-typed-inputs-in-my-first-custom-node-ever/21658/3 "2020-02-14T16:57:57Z")

</div>

> [@michaelblight](#):
>
> Is it just a matter of sequencing the priorities?

Hi Michael,  
Thanks for the assistance! Yes indeed, but in the early days I thought that the config screen contained the default values, which could be overwritten by a control message. But with the typedinput (containing an "msg" and a "num" option), which one of both you want ...

But at first sight your code snippet indeed should work. Will have to mention in my readme that the `resend_xxx` input message fields are read for legacy reasons ...

Thanks a lot!!  
Bart

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [14 April 2020 16:57 UTC](https://discourse.nodered.org/t/introducing-typed-inputs-in-my-first-custom-node-ever/21658/4 "2020-04-14T16:57:57Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
