-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
🔎 Search Terms
.includes
+ union
🕗 Version & Regression Information
Version 4.3.5
Playground link with relevant code
💻 Code
type MyType =
"X" | "Y" | "Z"
const myArray: MyType[ ] = [
"X", "Y", "Z"
]
let something = "string"
myArray.includes( something )
🙁 Actual behavior
TypeScript gives error on something
, while if I knew it existed in the myArray, I wouldn't have used the .includes
.
🙂 Expected behavior
My expectation is that I can send whatever string to .includes( )
and when getting back a true
be sure that string is of type MyType
. Then how else do you check if your string belongs to a union string type than having the code above? So I think the case of .includes( union type)
it should accept all the primitive types that array excepts.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created