Live data from Hacker News

CoffeeScript for TypeScript

civet.dev

1–10 of 143 posts

Re: CoffeeScript for TypeScript

#2
I'm not sure if getting some extra syntactic sugar is worth adopting a whole other language into a codebase: at least, that seemed to be one of the lessons from CoffeeScript.

Re: CoffeeScript for TypeScript

#3
Under "Everything is an Expression":

        items = (() => {
          const results = [];
          for (const item of items) {
            if (item.length) {
              results.push(item.toUpperCase());
            } else {
              results.push("");
            }
          }
          return results;
        })();

Seems like they are purposely making the JS version extra long. It could be:

        items = items.map(x => x.length > 0 ? x.toUpperCase() : ``)

Edit: Just realised the code on the right is the compiled code, not the "equivalent hand written JS".

Re: CoffeeScript for TypeScript

#5
post #2

I'm not sure if getting some extra syntactic sugar is worth adopting a whole other language into a codebase: at least, that seemed to be one of the lessons from CoffeeScript.

Eh, as long as the team is on board, and the sugar is simple enough and maps well to the underlying language without a ton of extra code, then I have no issues with it.

If it ever becomes a liability, you just check in the "transformed" code and it's gone.

Re: CoffeeScript for TypeScript

#7

Under "Everything is an Expression": items = (() => { const results = []; for (const item of items) { if (item.length) { results.push(item.toUpperCase()); } else { results.push(" "); } } return results; })(); Seems like they are purposely making the JS version extra long. It could be: items = items.map(x => x.length > 0 ? x.toUpperCase() : ` `) Edit: Just realised the code on the right is the compiled code, not the "…

[deleted]

Re: CoffeeScript for TypeScript

#8

Under "Everything is an Expression": items = (() => { const results = []; for (const item of items) { if (item.length) { results.push(item.toUpperCase()); } else { results.push(" "); } } return results; })(); Seems like they are purposely making the JS version extra long. It could be: items = items.map(x => x.length > 0 ? x.toUpperCase() : ` `) Edit: Just realised the code on the right is the compiled code, not the "…

[deleted]

Re: CoffeeScript for TypeScript

#9

Under "Everything is an Expression": items = (() => { const results = []; for (const item of items) { if (item.length) { results.push(item.toUpperCase()); } else { results.push(" "); } } return results; })(); Seems like they are purposely making the JS version extra long. It could be: items = items.map(x => x.length > 0 ? x.toUpperCase() : ` `) Edit: Just realised the code on the right is the compiled code, not the "…

My kingdom for "everything is an expression" in JS/TS, but that would likely require an entirely new language.

Re: CoffeeScript for TypeScript

#10

Under "Everything is an Expression": items = (() => { const results = []; for (const item of items) { if (item.length) { results.push(item.toUpperCase()); } else { results.push(" "); } } return results; })(); Seems like they are purposely making the JS version extra long. It could be: items = items.map(x => x.length > 0 ? x.toUpperCase() : ` `) Edit: Just realised the code on the right is the compiled code, not the "…

Given than in JS an empty string is a falsy value you can go even shorter:

     items = items.map(x => x.toUpperCase() || ``)
Post reply on HN