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 Ergonomics #1227

Open
SRachamim opened this issue Jun 3, 2020 · 7 comments
Open

Import Ergonomics #1227

SRachamim opened this issue Jun 3, 2020 · 7 comments

Comments

@SRachamim
Copy link
Contributor

SRachamim commented Jun 3, 2020

🚀 Feature request

I find it hard to manually and automatically import functions, types and utilities.

Current Behavior

This is how a typical file of mine looks:

import { pipe } from 'fp-ts/lib/pipeable';
import { flow } from 'fp-ts/lib/function';
import { either } from 'fp-ts';
import { Either } from `fp-ts/lib/Either';

// weird use of proofs
either.either

const anEither: Either = either.right(5);

Desired Behavior

I'de like to find everything on the index:

import { pipe, flow, Either } from 'fp-ts';

// general name for proofs (I'm an fp-noob, so maybe there's a better name)
Either.proof

// Either is both the module and the type
const either: Either = Either.right(5);

Suggested Solution

It could be better to pascal-case all modules on index.ts, and to export all types, all function utilities and pipe.

Consider also to export very handy utilities like sequence and traverse.

Who does this impact? Who is this for?

Tree shaking is not always relevant. In those cases I prefer ergonomics: auto-import should work like a charm and import should be grouped so it would be easy to manually import additional utilities.

@steida
Copy link
Contributor

steida commented Jun 3, 2020

It's already solved. Search in issues. Webpack 5 will tree-shake it properly.

@SRachamim
Copy link
Contributor Author

SRachamim commented Jun 6, 2020

What already solved? Tree-shaking is not the issue here.

@aqrln
Copy link

aqrln commented Jun 6, 2020

Hidden as the comments this was about are now deleted

Hey, let's keep the conversation civil and on track, because it becomes kinda heated.

@gcanti what do you think about adopting a Code of Conduct, such as https://www.contributor-covenant.org?

@aqrln
Copy link

aqrln commented Jun 6, 2020

@steida: what @SRachamim proposes is indeed a little bit more ergonomic than the current status quo outlined in the comment that you linked too, IMO. Consider that you won't need to choose between lib and es6 when confirming automatic imports, and won't have to import types and functions that operate on those types from different modules separately (import { either } from 'fp-ts' but import { Either } from 'fp-ts/lib/Either').

@SRachamim
Copy link
Contributor Author

@steida It's not hard to do what you recommend to me, it's just that I felt that my proposal wasn't clear enough.

The issue you linked to just talks about updating the documentation, while the current issue is a proposal to an entire shift in the import philosophy in the next major release.

@mikearnaldi
Copy link
Contributor

@steida: what @SRachamim proposes is indeed a little bit more ergonomic than the current status quo outlined in the comment that you linked too, IMO. Consider that you won't need to choose between lib and es6 when confirming automatic imports, and won't have to import types and functions that operate on those types from different modules separately (import { either } from 'fp-ts' but import { Either } from 'fp-ts/lib/Either').

The problem with this is tree shakability, yes you wouldn't have to choose between es6 & lib but the advantage of using es6 is rendered useless by the missing deep scope analysis on the webpack < 5 & rollup shakers.

The best solution would be to expose modules like:
import * as E from "fp-ts/Either"

This is possible by exposing each sub-package with it's own package.json referencing the esm module in "modules" like many other libraries do (e.g. @material-ui/core, @matechs/core)

I think this should be evaluated for v3 given it is really a pain point having to choose manually (or perform import-path-rewrite like the ecosystem libraries are forced to do)

@waynevanson
Copy link
Contributor

I think typeclass is the correct keyword here and the most suitable candidate I can conjure up.

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

5 participants