Skip to content

4.4 has incorrect output (.d.ts) when inferred from JSX proptypesΒ #45593

@frehner

Description

@frehner

Bug Report

πŸ”Ž Search Terms

proptypes
4.4 proptypes
prop types
proptype function

πŸ•— Version & Regression Information

  • This changed between versions 4.3.5 and 4.4

⏯ Playground Link

4.3 playground

declare function Select({ myFunc }: {
    myFunc?: any;
}): JSX.Element;

Now see the difference with 4.4 playground

declare function Select({ myFunc }: {
    myFunc?: null | undefined;
}): JSX.Element;

myFunc is no longer allowed to be, well, anything except null/undefined, when it should be any

Note that this appears to happen in 4.4 when I turn on strictNullChecks - if you turn that toggle off in 4.4, it goes back to the myFunc?: any; def, so there appears to be something going on there maybe? I can't tell if this is some sort of interaction with the new exactOptionalPropertyTypes toggle or what, though if I turn that off in 4.4 it still doesn't change the .d.ts. So 🀷

πŸ’» Code

import React from 'react'
import PropTypes from 'prop-types'

const Select = ({myFunc = null}) => {
  return <button onClick={() => myFunc?.()}>hi</button>
}

Select.propTypes = {
  myFunc: PropTypes.func
}

export default Select

πŸ™ Actual behavior

myFunc?: null | undefined;

myFunc is only allowed to be null | undefined

πŸ™‚ Expected behavior

myFunc?: any;

myFunc is any


From reading the release blog post, I don't notice anything that would appear to change this behavior. I could have misunderstood or missed it though!

Metadata

Metadata

Assignees

Labels

Domain: JSX/TSXRelates to the JSX parser and emitterWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions