idkjs
May 4, 2022, 4:19pm
1
Is it possible to create a variant type of emojis?
Im trying to emulate a ts type that looks like this:
type Emojis = "π" | "π" | "π"
This doesnt seem to work.
Maybe there is somewhere to get a named list of emojis that we could build a variant with?
type emojis = [ \"π" | \ "π" ]
Any suggestions would be greatly appreciated.
Thank you.
The following works with the polymorphic variants. Not sure whether thereβs a way to make it work with regular variants.
type emojis = [#"π" | #"π"]
let x: emojis = #"π"
Edit: although, not sure. #"π"
compiles to β\xf0\x9f\x98\x80β, and console.log("\xf0\x9f\x98\x80")
prints Γ°
2 Likes
Normally in strings youβd use backticks instead of double quotes to fix the problem, but it looks like you cannot use backticks in polymorphic variants, although you can circumvent it by using a %raw
call:
let x: emojis = %raw(`"π"`);
2 Likes
In the next release, strings will be UTF8 by default, even using regular double quotes, so this will be possible I think.
4 Likes