-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Confusion about the correct way to import from fp-ts #1606
Comments
blog posts amended |
@gcanti which blog posts are you referring to? Thanks! |
That seems to be only a list of blog posts, and I don't see anything specific to this question. Do you mind a direct link? |
@danielo515 the correct way to import from fp-ts is import ... from 'fp-ts/<module>' example with import * as Option from 'fp-ts/Option' |
That was my intuition, thanks for confirming.
There are, however, a lot of code examples wirh the other style of imports.
I think it will be useful to add a statement about this in the code
conventions section.
El mar, 24 oct 2023, 18:06, Giulio Canti ***@***.***>
escribió:
… @danielo515 <https://github.com/danielo515> the correct way to import
from fp-ts is
import ... from 'fp-ts/<module>'
example with Option:
import * as Option from 'fp-ts/Option'
—
Reply to this email directly, view it on GitHub
<#1606 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARKJWO5JX7F7TSWGNTULBTYA7RP7AVCNFSM5GQA76UKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZXG42TMMBSGY4Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@danielo515 in the |
Yes, years of medium (and similar) introductory articles to fp-ts:
https://www.thisdot.co/blog/functional-programming-in-typescript-using-the-fp-ts-library-deep-dive-into/
https://hvalls.dev/posts/intro-functional-fpts
https://zanza00.gitbook.io/learn-fp-ts/either
***@***.***/fp-ts-for-the-impatient-ad6c0a9a257b
And other docs in the ecosystem:
https://github.com/gcanti/fp-ts-local-storage
https://github.com/gcanti/fp-ts-laws
El mar, 24 oct 2023, 18:53, Giulio Canti ***@***.***>
escribió:
… @danielo515 <https://github.com/danielo515> in the src folder I found
these #1913 <#1913>, are there others?
—
Reply to this email directly, view it on GitHub
<#1606 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARKJWPNLXVT2BEZUUK5GIDYA7W65AVCNFSM5GQA76UKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZXG43DINBVGEZQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
📖 Documentation
I love
fp-ts
and I appreciate the good documentation. However I think that in most documentation the examples do not illustrate the "correct" way to import fromfp-ts
.Example: https://dev.to/gcanti/getting-started-with-fp-ts-monad-6k
The examples show e.g:
On the other hand #1241 has added support for
es6
imports that work well with tree shaking. This way of importing leaves the choice to the importing tool what version to consume, the commonjs or the es6 version (which is the recommended way to import). An example is:When mixing imports however we end up with multiple copies of
fp-ts
being used. This not only increases the size of the final bundle (if packed), it also breaks the concept of singletons. The constantOption.none
e.g. is probably supposed to be a singleton, but we end up with different instances depending on howfp-ts
gets imported.Libraries from the ecosystem address this via a post-processing step using
import-path-rewrite
which results in a correct result, by explicitly importing fromfp-ts/es6
for thees6
case. But this is basically unnecessarily complex, an import directly fromfp-ts
would work fine both for the es6 and the commonjs case, because of the entriesmain
andmodules
in thepackage.json
files. For exploiters offp-ts
it is also very easy to get this wrong, since the examples point to the commonjs import style, only.I suggest to clarify the intended import style in the
fp-ts
documentation and - if possible - rework the documentation to use the import directly fromfp-ts
instead of fromfp-ts/lib
.The text was updated successfully, but these errors were encountered: