Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import best practices #1003

Closed
steida opened this issue Nov 8, 2019 · 7 comments
Closed

import best practices #1003

steida opened this issue Nov 8, 2019 · 7 comments

Comments

@steida
Copy link
Contributor

steida commented Nov 8, 2019

📖 Documentation

When you are using both Option and IO, what is your best practice? * or aliasing?

import * as o from 'fp-ts/lib/Option';
import * as i from 'fp-ts/lib/IO';
import * as te from 'fp-ts/lib/TaskEither';
@DenisFrezzato
Copy link
Collaborator

I found myself (and I guess this is the more common approach among other fp-ts users) to import the whole module using the first letters of the module itself, for example:

import * as O from 'fp-ts/lib/Option'
import * as IO from 'fp-ts/lib/IO'
import * as TE from 'fp-ts/lib/TaskEither'

@raveclassic
Copy link
Collaborator

raveclassic commented Nov 9, 2019

I find writing imports by hand tedious and always rely on autocomplete/autoimport. Firstly I tried aliasing (fixing clashes by hand) but finally came to named imports from fp-ts index:

import { option, either } from 'fp-ts';

@steida
Copy link
Contributor Author

steida commented Nov 9, 2019

@raveclassic Interesting. Isn't either.Either verbose? Also, does it tree-shake?

@raveclassic
Copy link
Collaborator

raveclassic commented Nov 9, 2019

@steida except types :) only either.map, either.chain etc.

Downside - the whole either.ts module is always added to the bundle but it's worth the DX. Actually you also get the whole module bundled when importing under *

@steida
Copy link
Contributor Author

steida commented Nov 10, 2019

@raveclassic I like it. It's verbose but explicit and with autocomplete. As for tree shaking, it does not work reliably anyway when some other lib like monocle-ts is imported, because it will use /lib.

So, import { option, either } from 'fp-ts'; is ok and for tree shaking, we need imports rewriting anyway.

@steida
Copy link
Contributor Author

steida commented Nov 10, 2019

@raveclassic Still, I would love to solve tree shaking across fp-ts ecosystem anyway. It seems it's almost ready.

@steida
Copy link
Contributor Author

steida commented Nov 10, 2019

As a result, in the app, I would use import { option, either }.
In a lib, which is going to be tree shaked, it seems we have no other option than aliases. I doubt any tree shaking engine can optimize option.chain. It would have to solve clashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants