Skip to content

Known typescript sub-typing issues #207

@jamesrweb

Description

@jamesrweb

Expected Behavior

Typescript gets smart.

Actual Behavior

Typescript is not smart.

Steps to Reproduce the Problem

  1. View src/components/ReactP5WrapperGuard.tsx.
  2. View src/components/ReactP5WrapperWithSketch.tsx.
  3. Notice the as unknown as T shenanigans.

The as unknown as T casts are begrudgingly required due to a known limitation of the TypeScript compiler as demonstrated in the following issues for example:

As Ryan Cavanaugh points out:

"TS isn't capable of the higher-order reasoning needed to understand that Exclude<T, k> & { [k]: T[k] } is equivalent to T."

Note: this is the same issue as we face here just with Omit instead of Exclude.

Potentially this would have been resolved by this PR but the author closed it due to lack of time:

Perhaps someone interested in the topic and who has time to work on it would be willing to take a look into the issue.

Either way, until a resolution is merged into the TypeScript compiler that addresses this issue, we need to use this workaround. We could also remove this if we manage find a reasonable, more fitting workaround of some sort to avoid casting in the first place. If a workaround / change of implementation comes to mind, please raise an issue on the repository or feel free to open a PR!

Specifications

Package Version: 4.0.0 and above

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions