Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Relax no-null-undefined-union rule #4617

Closed
adidahiya opened this issue Mar 28, 2019 · 4 comments
Closed

Relax no-null-undefined-union rule #4617

adidahiya opened this issue Mar 28, 2019 · 4 comments

Comments

@adidahiya
Copy link
Contributor

especially as it pertains to React render functions, null | undefined is sometimes unavoidable when dealing with external type definitions.

from @styu:

the rule should be enforced on type definitions rather than on consumed types, so you wouldn’t be able to define types with the union, but could still consume types that have defined the union already. That way you can trend towards the right direction without encouraging the disabling of this rule due to external types

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Apr 2, 2019

Something like this

type Text = string | null

interface Props {
  title?: Text
}

Should be allowed, or at least having an options to be allowed.

It's more convenient to use ? to inform it's an optional props, even if the type already have null or undefined somewhere lost in his definition.

@adidahiya
Copy link
Contributor Author

@VincentLanglet if you want to allow that then it seems like you should just disable the rule altogether. It is a relatively strict style choice, definitely not for everyone

@VincentLanglet
Copy link
Contributor

See #4625 (comment)

? is more than undefined

interface A {
 a: number | undefined
}
interface B {
 b?: number
}

const a: A = {} // $error
const b: B = {} // no error

Plus the actual tslint:all has conflict between this rule and no-null-keyword.

@glen-84
Copy link
Contributor

glen-84 commented Apr 22, 2019

@adidahiya This was fixed in #4625.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants