4 ms·
TypeScript appears to compile even in the face of undefined variables. Just went to the playground and dropped a random jQuery sample in: http://www.typescript
by kmontrose 13y ago
TypeScript appears to compile even in the face of undefined variables.
Just went to the playground and dropped a random jQuery sample in: http://www.typescriptlang.org/Playground/#src=%24(%20document%20).ready(function()%20%7B%0D%0A%20%0D%0A%20%20%20%20%24(%20%22a%22%20).click(function(%20event%20)%20%7B%0D%0A%20%0D%0A%20%20%20%20%20%20%20%20alert(%20%22Thanks%20for%20visiting!%22%20)%3B%0D%0A%20%0D%0A%20%20%20%20%7D)%3B%0D%0A%20%0D%0A%7D)%3B http://www.typescriptlang.org/Playground/#src=%24(%20documen...
You get squiggles yes, but you also get valid javascript. So it looks like you can paste random javascript into TypeScript and get it to compile. I went and tried with the actual compiler (to make sure it's not some artifact of the playground website), and confirmed you get a proper .js file out (and 2 messages, about $ being undefined).
Quick google makes it sound like getting rid of the squiggles / messages is pretty easy: http://stackoverflow.com/a/12755602/80572 http://stackoverflow.com/a/12755602/80572
I'm not sold on TypeScript yet (or any of the transpiled javascript languages, honestly), but this:
> False. Typescript will choke on most JavaScript files from the web.
Seems to be the actual false statement in this thread.
- c0achmcguirk 13y agoThanks for trying that out the jQuery example. They look to be making the compiler (or the playground site) more permissive lately. This didn't work in May when I last tried it out. I've used the typescript compiler on a randomly-chosen JS library (typeface.js http://typeface.neocracy.org/typeface-0.15.js http://typeface.neocracy.org/typeface-0.15.js ) and it had dozens of compiler errors for me to fix before it would compile. The playground is now accepting them for some odd reason. This seems to be recent behavior or perhaps the node.js version of the compiler behaves differently?
- seanmcdirmid 13y agoThe title of the article is "...the Road to 1.0", you can imagine that they are continuously improving it to get there.
- rictic 13y agoOne thing that threw me off initially is the fact that typescript will complain about errors, but still do the translation of TS -> JS. For example: var s = 'hello'; s.toExponential(); Typescript tells you about the obvious error that there's no property 'toExponential' on strings, but it also merrily produces yourfilename.js. In my experience so long as you don't have any syntax errors, tsc will give you back javascript. This is partly because the translation from typescript to javascript is incredibly straightforwards and ignores the types completely. Writing a nonvalidating, dumb but super fast ts -> js transpiler is about an afternoon's worth of work, especially if you bootstrapped from the typescript parser and tests.