Skip to content

null and undefined are missing in createSignal return type #972

@julvo

Description

@julvo

Describe the bug

When creating a signal with a union type that includes null or undefined, the resulting signal doesn't include null or undefined.

E.g. if we create a signal that can be null or a number using createSignal<null | number>(null), the return type is Signal<number> instead of Signal<number | null>

The issue is that the value of the signal is actually null, but the type signature doesn't reflect that. That means we loose type-safety.

Your Example Website or App

https://playground.solidjs.com/?version=1.3.13#NobwRAdghgtgpmAXGGUCWEwBowBcCeADgsrgM4Ae2YZA9gK4BOAxiWGjIbY7gAQi9GcCABM4jXgF9eAM0a0YvADo1aAGzQiAtACsyAegDucAEYqA3EogcuPfr2ZCouOAGU0Ac2hqps+YpU6DW09CysrGXoIZlw0WgheAGEGCBdGAAoASn4rXgd4sj5gZhTcLF4yOFxkqNwAXV4AXgcnF3cvKDUAHgh6GBNxXgAfXl61NQA+dLG1TMsE-IhC3gxHOHhUpt4spomKqprU9JLanYBqXgBGOdzlBf19XgADKCeVsl5aGV4CYmfe-riN4meh8MgACwYahEvAG-z6AwkIxmT1uJSWfCgWxOR0y4QWQlwTAS6VueS6INwuHiPyIcEaKkp1IgKk+EESGmYAGtGiBVkINrhJBMyXl+DjcFlJKK8iAoNKFuT9Ez4iKFjcIAqrEJROJ0jtGnsuoc0rx9BNyiJaMw+sJcAA6DxVACianWdoAQvgAJIiUlgKCEQgqTIasCSOpAA

Steps to Reproduce the Bug or Issue

  1. Create a signal with a nullable type, e.g. number | null
  2. Observe that resulting signal type doesn't include null, e.g. only number instead of number | null

Expected behavior

When using createSignal<T | null>(null), I'd expect the resulting signal to be of type Signal<T | null>

Screenshots or Videos

Example from the Solid playground with createSignal<number | null>()
image (18)

Also an issue when creating a nullable signal using createSignal<number>(), where I'd expect the return type to be Signal<number | undefined>
image (19)

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

The issue may be related to #217, but that issue was focused on initialising without arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions