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

fix TypeScript typings exports #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

roymiloh
Copy link

@roymiloh roymiloh commented Jun 10, 2018

Hi,

So this one is pretty interesting - currently it seems like you expect people to import create-react-context this way (because declaration file specifies export default ...):

import createReactContext from 'create-react-context';

export const context = createReactContext(null);

The TypeScript compilation result is:

// my-app/context.js
var create_react_context_1 = require("create-react-context");
exports.context = create_react_context_1.default(null);

However, in create-react-context production (transpiled) version, we have:

// create-react-context/lib/index.js
exports.default = _react2.default.createContext || _implementation2.default;
// this is the problematic line
module.exports = exports['default'];

So obviously previous create_react_context_1.default is undefined.

Two possible solutions (1) dropping the module.exports line (happens due to this plugin), or (2) accept this PR, and then client would import this way:

import * as createReactContext from 'create-react-context';
// or:
import createReactContext = require('create-react-context');

Dropping module.exports means that clients who don't use es2015 modules would've to import this way:

const {default: createReactContext} = require('create-react-context');

... and maybe it's a breaking change (although it's not documented).

I suggest to accept this PR (and keep module.export - PR is based on having it), as typings are broken anyway - no idea how people use it in current state.

@jamiebuilds please.

@TrySound
Copy link

Importing function as a namespace is the biggest failure of typescript. Key-value object just cannot be a function.

import * as createReactContext from 'create-react-context';

Some guys said me the problem can be solved with more flexible interop option.

@roymiloh
Copy link
Author

Failure or not (yeah, it's a workaround that TypeScript upholds) - currently it just does not work:)

@TrySound
Copy link

Workaround in every package is broken ecosystem.

@rhalukongor
Copy link

Here to confirm the problem. The library can not be consumed by a Typescript project as of now.

@TrySound
Copy link

Can't you play with some options to solve the problem on your side?

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

Successfully merging this pull request may close these issues.

4 participants