Closed imteekay closed 1 year ago
The exercise is open-ended, although it'll work better if you assign some type to string literals. For a miniature compiler, the typeof
approach you use is fine -- you're re-using the representation of strings from Javascript so you can reuse typeof
. For a full-size compiler, you'll want to add a field when you parse a literal that tracks its kind.
Hi @sandersn, I'm working on the third exercise "Add string literals".
Does the exercise require adding type-checking to the string literals too? Or adding a token and parsing it is enough?
This is the wip PR: https://github.com/imteekay/mini-typescript/pull/4
Edit: I'm studying how the type checker works and was able to type check string literals using
typeof
for the expression values (https://github.com/imteekay/mini-typescript/pull/4/commits/a1df2c712338ca532dfc04a017e9deb7db03dd35). I also complemented thesingleTypedVar
test to cover this implementation. But still not sure if using thetypeof
is the right approach here.