Live data from Hacker News

Starting a TypeScript Project in 2021

metachris.com

71–80 of 190 posts

Re: Starting a TypeScript Project in 2021

#71

esbuild sounds promising as one friction point was that the TS compiler would compile all your TS files into JS files but there was no way to bundle them together into one JS file you could include in your HTML and webpack takes a bit to setup. It looks like esbuild doesn’t have websocket auto-reload magic so will need to refresh the web browser to see the recompiled changes.

> but there was no way to bundle them together into one JS file you could include in your HTML and webpack takes a bit to setup Maybe I am misunderstanding but this feels like it is provided via the `--bundle` flag in esbuild [1]. > It looks like esbuild doesn’t have websocket auto-reload magic so will need to refresh the web browser to see the recompiled changes. I have also noticed that it does not seem to have the…

Thanks. I meant that `tsc` has no `--bundle` flag

Re: Starting a TypeScript Project in 2021

#72
If you haven't already, give a try to ViteJS.

It's from the author of Vue, and support both Vue and React, including JSX and TS.

It has the qualities of Vue:

- it works out of the box

- setup and usage are super easy

- it's wicked fast

- documentation rocks

I talked about it to one of my client 3 days ago. They tried it 5 minutes and decided to spend a day migrated their project immediately.

It's that good.

And the migration took only 2 hours.

Re: Starting a TypeScript Project in 2021

#73
post #63
post #42

Earlier quoted context omitted.

tsconfig's noUnusedLocals can help you with the last one.

And it allows you to opt out when needed by starting the variable with an underscore, which is much nicer than eslint-disable-next-line...

That's configurable in the rule though.

https://eslint.org/docs/rules/no-unused-vars#varsignorepatte...

Re: Starting a TypeScript Project in 2021

#74
post #16

Earlier quoted context omitted.

No it's a replacement for Node.

Please stop spreading this misnomer. It's an alternative platform. It's absolutely not a wholesale replacement, and its inner workings are vastly different to Node. Edit: Well, someone touched a nerve! Doubt me, downvoters? You need but google to find a wealth of information to support the statement. https://www.imaginarycloud.com/blog/deno-vs-node/ is the first result, and there are a litany of other articles explai…

I have in mind to use Deno instead of both Node and Bash scripts :- )

Re: Starting a TypeScript Project in 2021

#75

Ever since watching Jonathan blows talk "Preventing the collapse of civilisation", I've been mulling over things like this. It feels like we have this defacto set of commands you have to run to start a new Node/Typescript project, without much understand of what it does. Then you get complier or lint errors and then spend ages googling around for the answer that tells you to change a specific flag. This isn't a compl…

I recently was trying to diagnose a bug with React state in someone else's project. Everything I found said "install the React extension". Okay but this thing boils down to just JavaScript right? I ultimately failed to find out how to inspect anything meaningful without the extension -- it's almost as if nobody knows how React works. The abstraction is bananas. Sure, JavaScript sucks but is this better?

I swore off massive impenetrable abstractions like React eons ago and I'm saner for it. Abstractions are supposed to remove complexity, not treat users like morons.

Re: Starting a TypeScript Project in 2021

#76

Ever since watching Jonathan blows talk "Preventing the collapse of civilisation", I've been mulling over things like this. It feels like we have this defacto set of commands you have to run to start a new Node/Typescript project, without much understand of what it does. Then you get complier or lint errors and then spend ages googling around for the answer that tells you to change a specific flag. This isn't a compl…

The nice thing is you don’t need all this stuff it’s just one persons opinion of what you need. It’s mostly that you get a bunch of extra functionality with it. Additive rather than required.

I feel like I went through exponentially more faffing about setting up the web server and forwarding to the accompanying Go server on DigitalOcean than I did getting my project running in modern browsers just using tsc.

Re: Starting a TypeScript Project in 2021

#77
post #73
post #63

Earlier quoted context omitted.

And it allows you to opt out when needed by starting the variable with an underscore, which is much nicer than eslint-disable-next-line...

That's configurable in the rule though. https://eslint.org/docs/rules/no-unused-vars#varsignorepatte...

Ah nice, I didn't know that. Thanks.

Re: Starting a TypeScript Project in 2021

#78

Ever since watching Jonathan blows talk "Preventing the collapse of civilisation", I've been mulling over things like this. It feels like we have this defacto set of commands you have to run to start a new Node/Typescript project, without much understand of what it does. Then you get complier or lint errors and then spend ages googling around for the answer that tells you to change a specific flag. This isn't a compl…

I recently was trying to diagnose a bug with React state in someone else's project. Everything I found said "install the React extension". Okay but this thing boils down to just JavaScript right? I ultimately failed to find out how to inspect anything meaningful without the extension -- it's almost as if nobody knows how React works. The abstraction is bananas. Sure, JavaScript sucks but is this better? I swore off m…

When you're trying to debug a JavaScript error do you use Chrome's built in JavaScript debugger, or do run Chrome in GDB? Or perhaps you get out your oscilloscope and try attaching it to your CPU? Debugging at multiple levels of abstraction is nothing new.

The fact that there are debugging tools at the React level does reduce complexity. It means you don't need to understand the details of how React is implemented. You can just think in terms of React concepts (which are quite straightforward and have excellent documentation).

Re: Starting a TypeScript Project in 2021

#79

I really recommend getting comfortable with make -- if you know just enough to be dangerous (PHONY targets, regular targets, ifeq, ?=), it can be an incredibly useful tool, and unify control/operations across projects. The complexity/required reading that comes with integrating ~5+ individual tools and libraries you have to be aware of across one language can be made a lot easier by using make to do the plumbing betw…

How do you pass arguments to your Make targets? Let's say you'd like to set `DB_USER` to "my_name", then, do you: make psql user=my_name # ? To me, having to type `user=` is very annoying, I want to do just `make psql my_name`. Agreed that Make is nice :- ) My Makefile is not as nice as Make though o.O > I'm not excited about writing a bash script Bash scripts almost could be illegal :- ) I'm thinking about writing s…

Lots of ways! So this is one of those things that's subtly quite interesting -- Make will both take all variables from the environment, and make them Make variables. So this command:

    $ USER=my_name make psql
The above example is the creation of a temporary ENV variable (assuming your shell supports this feature, it's equivalent to doing an export but only for that line), and the USER variable (accessed by using $(USER) or ${USER} in your makefile somewhere) will be automatically populated.

That is distinct from the following:

    $ make psql USER=my_name
What you've done there is actually make-specific, you're giving make a Make variable, so Make will know about $(USER)/${USER}, and it will also show up, because Make exposes it's variables to shells (each line is it's own shell) that is run[0]. So this Makefile:

   .PHONY: my-tgt

   my-tgt:
     echo -e "double dollar to print a bash var => $$MYVAR"
Produces the same thing -- $$MYVAR is actually a way to use a shell variable (the $ has to be escaped), but you get the same result putting USER= before and after:

    $ MYVAR=from-the-shell make my-tgt                                                                                                            
    double dollar to print a bash var => [from-the-shell]
    $ make my-tgt MYVAR=from-make                                                                                                                 
    double dollar to print a bash var => [from-make]
All that said, if you don't need to ever change the name then just make the target `psql-` or `psql_username`, problem solved! For example, I use kubie on my kubernetes cluster, and I have explicitly named clusters, so when I want to enter a kubie context (just so I can avoid some typing), I run `make -kubie` and I'm off -- I didn't feel the need to do `make kubie CLUSTER=` though I easily could have. Here's what it actually looks like:

    mycluster-kubie:
     CLUSTER=mycluster $(KUBIE) ctx -f secrets/ansible/the.dns.name.of.my.server/var/lib/k0s/pki/admin.conf
I don't strictly need that CLUSTER=mycluster there, but if the command cared, then it could be easily "hard coded".

> Bash scripts almost could be illegal :- ) I'm thinking about writing scripts in Deno in the future, instead

Bash is super powerful, and some people are good at it, but it just hasn't stuck enough for me to be comfortable. Plus, it still feels like another language to be wrangled while Make's only purpose is to do the things (whatever that thing is) that build your software.

[EDIT] figured I might share some more nice pieces of software that I use and love (also so you don't think I'm just willy nilly checking in secrets to my repository):

- direnv[1] for managing local ENV settings in a given folder (like your project folder)

- git-crypt[2] for simple encryption of secrets in a git repository, with gpg support

- entr[3] it re-runs a given command when files change, really good for reducing feedback loops when working with tooling that doesn't have --watch/fsnotify functionality

[0]: https://www.gnu.org/software/make/manual/html_node/Environme...

[1]: https://direnv.net/docs/hook.html

[2]: https://www.agwa.name/projects/git-crypt/

[3]: https://eradman.com/entrproject/

Re: Starting a TypeScript Project in 2021

#80

I really recommend getting comfortable with make -- if you know just enough to be dangerous (PHONY targets, regular targets, ifeq, ?=), it can be an incredibly useful tool, and unify control/operations across projects. The complexity/required reading that comes with integrating ~5+ individual tools and libraries you have to be aware of across one language can be made a lot easier by using make to do the plumbing betw…

How do you pass arguments to your Make targets? Let's say you'd like to set `DB_USER` to "my_name", then, do you: make psql user=my_name # ? To me, having to type `user=` is very annoying, I want to do just `make psql my_name`. Agreed that Make is nice :- ) My Makefile is not as nice as Make though o.O > I'm not excited about writing a bash script Bash scripts almost could be illegal :- ) I'm thinking about writing s…

Huh? But bash is super powerful? I can go from zero to a script that's production ready in like an hour with option support, help text, man pages, shell completion, signal handling that's portable to any system.

I also like Python for this but it's an absolute PITA to distribute scripts that support lots of different versions of python or need any dependencies not in your distro's repos.

Post reply on HN