Language: TypeScript
I program in JavaScript, because I value isomorphic code (using the same code on the client and the server), being able to implement server-side rendering more easily, and programming in only one language in general. In terms of flavor, I prefer TypeScript (93% satisfaction) over vanilla ES6, because static typing catches a lot of bugs before they happen.
Might change soon? Very UnlikelySetup
TypeScript is automatically configured by Next, but we need to install it as a dev dependency:
- Yarn
- NPM
yarn add -D typescript
npm i -D typescript
I also often end up installing ts-node
to execute TS files, or ts-node-dev
to restart the Node process on file changes while developing, both in transpile-only mode.
I also set an absolute path for imports:
"compilerOptions": {
"baseUrl": "src",
"paths": {
"#/*": ["*"]
},
// ...
}
Which allows me to import files this way:
import Header from '#/components/Header'
Pick whatever symbol you like. A lot of people use @/
but I find it confusing because scoped packages also start with @
.
It is natively supported by Next, but if you are not using Next, you might need tsconfig-paths to get those paths to work with Node, ts-node
, and ts-node-dev
:
"scripts": {
"with-node": "node -r tsconfig-paths/register main.js",
"with-ts-node": "ts-node -r tsconfig-paths/register main.ts",
"with-ts-node-dev": "tsnd --respawn -r tsconfig-paths/register main.ts"
}
Note: If ts-node
is used in production, it should have the --transpile-only
flag.
I also set module
to commonjs
for a broader compatibility with NPM modules:
"compilerOptions": {
"module": "commonjs",
// ...
}
Alternatives
I find TypeScript more reliable than Flow, and it has a much bigger community and support. I would recommend Python to someone learning the fundamentals of programming though.