Skip to content

[@types/react] Booleanish prop definitions cause issues when destructuring props #41419

@cascornelissen

Description

@cascornelissen
  • I tried using the @types/react package and had problems.
  • I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • Mention the authors (see Definitions by: in index.d.ts) so they can respond.

A couple of projects we're working on contain React components that allow any available HTML attribute to be passed to them. We use React.HTMLProps to extend the component-specific props for this.

import React from 'react';

interface Props extends React.HTMLProps<HTMLDivElement> {}

export default class Example extends React.Component<Props> {
    render() {
        const { ...props } = this.props;
        
        return <div {...props}/>;
    }
}

The types for a few props (like contentEditable) have been changed in #40658 (released as version 16.9.4) which breaks this with the following error:

TS2322: Type '{ accept?: string | undefined; acceptCharset?: string | undefined; action?: string | undefined; allowFullScreen?: boolean | undefined; allowTransparency?: boolean | undefined; alt?: string | undefined; ... 354 more ...; key?: string | ... 1 more ... | undefined; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.   Type '{ accept?: string | undefined; acceptCharset?: string | undefined; action?: string | undefined; allowFullScreen?: boolean | undefined; allowTransparency?: boolean | undefined; alt?: string | undefined; ... 354 more ...; key?: string | ... 1 more ... | undefined; }' is not assignable to type 'HTMLAttributes<HTMLDivElement>'.     Types of property 'contentEditable' are incompatible.       Type 'boolean | "true" | "false" | "inherit" | undefined' is not assignable to type 'boolean | undefined'.

The changes in #40658 resulted in the contentEditable prop having a type of 'boolean | "true" | "false" | "inherit" | undefined' while the HTMLDivElement > HTMLElement > ElementContentEditable has a type of 'boolean | undefined'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions