You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Mock dataconstarr=["one","two","three","four"];// Expected behaviour when using the utility type itselftypetestTrue1=Includes<["one","two","three","four"],"one">;// true ✓typetestTrue2=Includes<["one","two","three","four"],"nine">;// false ✓typetestTrue3=Includes<["one","two","three","four"],9>;// false ✓// Passing the array as type argumenttypetestFalse1=Includes<typeofarr,"one">;// false, has to be true ↯typetestFalse4=Includes<typeofarr,"nine">;// false// Using type isElementInArraytypetestError1=isElementInArray(arr,"one");// Parsing error: ';' expected. ↯typetestError2=isElementInArray(arr,"two");// Parsing error: ';' expected. ↯
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Can anyone show me an example of the practical use of the Includes Challenge?
Link to Challenge
TS Playground
Solution
Maybe it makes no sense to create a function when the utility type already does everything.
Usage
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions