Skip to content

Commit

Permalink
Fix types for TS projects not using esModuleInterop (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-stripe authored Feb 6, 2020
1 parent 1f7079e commit 39b5c7c
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 21 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
],
"jest": {
"preset": "ts-jest/presets/js-with-ts",
"setupFilesAfterEnv": [
"<rootDir>/test/setupJest.js"
]
"setupFilesAfterEnv": ["<rootDir>/test/setupJest.js"],
"globals": {"ts-jest": {"diagnostics": {"ignoreCodes": [151001]}}}
},
"dependencies": {
"prop-types": "^15.7.2"
Expand Down
13 changes: 11 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export default [
},
},
],
plugins: [ts(), resolve(), babel(), commonjs()],
plugins: [
ts(),
resolve(),
babel(),
commonjs({
namedExports: {'prop-types': ['func', 'object', 'any', 'string']},
}),
],
},
// Minified UMD Build without PropTypes
{
Expand All @@ -51,7 +58,9 @@ export default [
resolve(),
babel(),
replace({'process.env.NODE_ENV': JSON.stringify('production')}),
commonjs(),
commonjs({
namedExports: {'prop-types': ['func', 'object', 'any', 'string']},
}),
terser(),
],
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Elements.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import {act} from 'react-dom/test-utils';
import {mount} from 'enzyme';
import {Elements, useElements, useStripe, ElementsConsumer} from './Elements';
Expand Down
5 changes: 3 additions & 2 deletions src/components/Elements.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {
import * as React from 'react';
import {
useContext,
useMemo,
useState,
Expand All @@ -7,7 +8,7 @@ import React, {
ReactNode,
ReactElement,
} from 'react';
import PropTypes from 'prop-types';
import * as PropTypes from 'prop-types';
import * as stripeJs from '@stripe/stripe-js';

import {isEqual} from '../utils/isEqual';
Expand Down
10 changes: 3 additions & 7 deletions src/components/createElementComponent.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React, {useLayoutEffect} from 'react';
import * as React from 'react';
import {useLayoutEffect} from 'react';
import {mount} from 'enzyme';
import {Elements} from './Elements';
import createElementComponent from './createElementComponent';
import {mockElements, mockElement, mockStripe} from '../../test/mocks';

jest.mock('react', () => {
const actual = jest.requireActual('react');
jest.spyOn(actual, 'useLayoutEffect');
return actual;
});

describe('createElementComponent', () => {
let stripe;
let elements;
Expand All @@ -27,6 +22,7 @@ describe('createElementComponent', () => {
element = mockElement();
stripe.elements.mockReturnValue(elements);
elements.create.mockReturnValue(element);
jest.spyOn(React, 'useLayoutEffect');
element.on = jest.fn((event, fn) => {
switch (event) {
case 'change':
Expand Down
5 changes: 3 additions & 2 deletions src/components/createElementComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useRef, useEffect, useLayoutEffect} from 'react';
import PropTypes from 'prop-types';
import * as React from 'react';
import {useRef, useEffect, useLayoutEffect} from 'react';
import * as PropTypes from 'prop-types';
import * as stripeJs from '@stripe/stripe-js';

import {useElementsContextWithUseCase} from './Elements';
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import * as stripeJs from '@stripe/stripe-js';

export interface ElementProps {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/usePrevious.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import {mount} from 'enzyme';
import {usePrevious} from './usePrevious';

Expand Down
2 changes: 1 addition & 1 deletion test/setupJest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {configure} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import * as Adapter from 'enzyme-adapter-react-16';

configure({adapter: new Adapter()});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"removeComments": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
"esModuleInterop": false // Must remain `false` to emit types compatible with other projects not using `esModuleInterop`
},
"include": ["./src"]
}
Expand Down

0 comments on commit 39b5c7c

Please sign in to comment.