An opinionated ESLint config to encourage pure(ish), typeful functional programming in TypeScript.
yarn add --dev eslint-config-typed-fp \
@typescript-eslint/eslint-plugin \
@typescript-eslint/parser \
eslint \
eslint-plugin-functional \
eslint-plugin-total-functions \
typescript
- Turn on TypeScript's strict mode and noUncheckedIndexedAccess option.
- Set up ESLint + TypeScript.
- Update your
.eslintrc.js
:
module.exports = {
+ parser: "@typescript-eslint/parser",
parserOptions: {
+ project: "./tsconfig.json",
+ ecmaVersion: 2018,
+ sourceType: "module"
},
extends: [
+ "typed-fp",
...
],
plugins: [
+ "@typescript-eslint",
+ "functional",
+ "total-functions",
...
],
rules: {
...
}
};
Basically,
- the recommended rules from ESLint itself,
- the strict and recommended-requiring-type-checking rules from typescript-eslint,
- the strict rules from eslint-plugin-functional,
- the recommended rules from my own eslint-plugin-total-functions, plus
- a selection of rules not included in the recommended rulesets from all the above to encourage typed, functional programming.
See the extends
and rules
sections in index.ts for the details.
Check out the TODOs in index.ts and of course the issues. Contributions welcome.
TypeScript (in)famously considers slavish adherance to type-safety and soundness (at least at the cost of developer ergonomics) a non-goal. With this ESLint config we take the opposite position.
Here's a selection of articles to motivate "why typed FP":
- the case for immutability from immutable-js
- The abject failure of weak typing - Ken Scambler
- No, dynamic type systems are not inherently more open - Alexis King
- Parse, don’t validate - Alexis King
- Types as axioms, or: playing god with static types - Alexis King
- There are more types than classes - Stephen Compall
- Dynamic Languages are Static Languages - Robert Harper
- Static Optimizability from From first principles: Why I bet on Scala.js - Li Haoyi
- From Rust to TypeScript - Alan Darmasaputra
- https://counterexamples.org/
- TypeScript for Functional Programmers
- Typed functional programming in TypeScript (fp-ts)
- https://github.com/danielnixon/eslint-plugin-total-functions
- https://github.com/agiledigital/readonly-types
- https://github.com/eslint-functional/eslint-plugin-functional
- https://github.com/gcanti/fp-ts
- https://github.com/plantain-00/type-coverage (and its strict mode)
- https://github.com/immutable-js/immutable-js
- https://github.com/uhyo/better-typescript-lib