the literal values are used in the source code itself. So
either update all occurrences of "Facebook" in the source code; impossible if it is used in code you don't control.
or just leave it as is and hope nobody complains that it should be "Meta", not "Facebook".
Trade-offs ...
Added bonus: iterability
constallBigTechz=Object.values(bigTechz);// Using type predicates// https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates//functionisBigTechz(name:string):nameisBigTechz{return(allBigTechzasstring[]).includes(name);}constmyFav=bigTechz.Apple;console.log(isBigTechz(myFav));// trueconsole.log(isBigTechz('Walmart'));// falseconstformatter=newIntl.ListFormat('en',{style:'long',type:'conjunction',});console.log(`The BigTechz: ${formatter.format(allBigTechz)}`);// "The BigTechz: Google, Apple, Amazon, and Meta"
We start with
Then 2021-10-28
No need to change
bigTechz.Facebook
anywhere in your code and more importantly in code you don't control (but that uses your code).With
the literal values are used in the source code itself. So
Trade-offs ...
Added bonus: iterability
Thanks @peerreynders !
Good point!
iterability
can be a big plus.Now your method is starting to look handy! Thank you!