DEV Community

Discussion on: TypeScript Gotchas

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited
  • A gotcha I met recently is Browserified TypeScript's private fields aren't private.
    • It might be better to prefix with underscore, just like Python.
  • On publishing a library, source code isn't bundled by default. Have to declaration: true and declarationMap: true in tsconfig.json.

Solution: you should decode anything that you don't know the type of. I recommend bringing in a library like io-ts for the job.

I use runtypes, or just ajv. Is there a benefit to switching to io-ts? Also, learn fp-ts?

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

In the first example, it just looks like types need to be declared, turning on strict mode would help as well.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Yes, I am talking from the perspective of Browser's JavaScript console; and non-Node.js developers.

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Sorry I commented in the wrong place haha.

Collapse
 
edbentley profile image
Ed Bentley

Those look like great options too, though I haven't tried them myself. The io-ts API has worked well for me so I've stuck to it. Whether to use fp-ts or not would need another blog post to discuss! Generally I don't let the fp-ts types like Either propagate to the rest of my code, but it's really up to whatever you prefer.