Supercharge your Poi config file with TypeScript

EGOIST
Poi - delightful web development
1 min readJan 8, 2018

Poi maintains a sane list of options to let you customize it, however it might still be painful to remember those options if you’re new to Poi.

So the solution is, you can already tell by the title, TypeScript to the Rescue.

TypeScript VSCode intellisense

It’s really easy to use TypeScript to write Poi config, simply use poi.config.ts instead of poi.config.js :

// Require `poi^9.6.11`
import { Options } from 'poi'
const options: Options = {
entry: 'src/index.js'
}
export default options

To use the file, run:

poi --require ts-node/register --config poi.config.ts

Poi by default doesn’t understand what .ts file is, that’s why you require ts-node here to transform TypeScript to JavaScript.

If you want type-checking in poi.config.js instead of .ts file, you can require babel-register and use corresponding presets instead since you only need to transform ES modules:

// @ts-check
import
{ Options } from 'poi'
/** @type {Options} */
const options = {
entry: 'src/index.js'
}
export default options

--

--