Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - what is the 'unique' keyword for?

Tags:

typescript

I'm just writing some code in the TypeScript playground, and found that unique appears to be a reserved word, but I can't find any documentation for it.

enter image description here

Is there any documentation on this keyword anywhere?

like image 746
Matthew Layton Avatar asked Mar 23 '18 14:03

Matthew Layton


1 Answers

As of TypeScript 2.7 there is a unique symbol type which is used to allow using symbols as unique literals. The relevant documentation is here, and @TitianCernicovaDragomir linked the relevant pull request that introduced this functionality.


As for why it's blue in the Playground, I guess its colorization isn't the best and just highlights any special word even if it's not being used in a special context. (I can't find a relevant GitHub issue about it; maybe someone should file one?). It's definitely a valid identifier, and the emitted JavaScript is correct. VSCode doesn't seem to have this issue:

Compare Playground weird colorizing:

weird Playground colors

to VSCode expected colorizing:

VSCode colors

Oh well. Hope that helps; good luck!

like image 109
jcalz Avatar answered Oct 21 '22 09:10

jcalz