diff --git a/.changeset/hot-yaks-flow.md b/.changeset/hot-yaks-flow.md new file mode 100644 index 000000000..a6c9313f8 --- /dev/null +++ b/.changeset/hot-yaks-flow.md @@ -0,0 +1,5 @@ +--- +'@emotion/is-prop-valid': minor +--- + +Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written. diff --git a/packages/is-prop-valid/package.json b/packages/is-prop-valid/package.json index 03f0b6d55..148782dfa 100644 --- a/packages/is-prop-valid/package.json +++ b/packages/is-prop-valid/package.json @@ -4,7 +4,7 @@ "description": "A function to check whether a prop is valid for HTML and SVG elements", "main": "dist/emotion-is-prop-valid.cjs.js", "module": "dist/emotion-is-prop-valid.esm.js", - "types": "types/index.d.ts", + "types": "dist/emotion-is-prop-valid.cjs.d.ts", "license": "MIT", "repository": "https://github.com/emotion-js/emotion/tree/main/packages/is-prop-valid", "scripts": { @@ -21,8 +21,7 @@ }, "files": [ "src", - "dist", - "types/*.d.ts" + "dist" ], "browser": { "./dist/emotion-is-prop-valid.cjs.js": "./dist/emotion-is-prop-valid.browser.cjs.js", diff --git a/packages/is-prop-valid/src/index.js b/packages/is-prop-valid/src/index.ts similarity index 76% rename from packages/is-prop-valid/src/index.js rename to packages/is-prop-valid/src/index.ts index 2e847785b..88fb41532 100644 --- a/packages/is-prop-valid/src/index.js +++ b/packages/is-prop-valid/src/index.ts @@ -1,11 +1,9 @@ import memoize from '@emotion/memoize' -/* -declare var codegen: { require: string => RegExp } -*/ +declare const codegen: { require: (path: string) => any } // eslint-disable-next-line no-undef -const reactPropsRegex = codegen.require('./props') +const reactPropsRegex: RegExp = codegen.require('./props') // https://esbench.com/bench/5bfee68a4cd7e6009ef61d23 const isPropValid = /* #__PURE__ */ memoize( diff --git a/packages/is-prop-valid/src/props.js b/packages/is-prop-valid/src/props.js index 873fa118d..326d7898b 100644 --- a/packages/is-prop-valid/src/props.js +++ b/packages/is-prop-valid/src/props.js @@ -1,3 +1,6 @@ +/** + * This module needs to remain pure JavaScript for codegen to work on it + */ const props = { // react props // https://github.com/facebook/react/blob/5495a7f24aef85ba6937truetrue1ce962673ca9f5fde6/src/renderers/dom/shared/hooks/ReactDOMUnknownPropertyHook.js diff --git a/packages/is-prop-valid/types/index.d.ts b/packages/is-prop-valid/types/index.d.ts index 2ca137567..ad44a5b20 100644 --- a/packages/is-prop-valid/types/index.d.ts +++ b/packages/is-prop-valid/types/index.d.ts @@ -1,5 +1,3 @@ -// Definitions by: Junyoung Clare Jang // TypeScript Version: 2.1 -declare function isPropValid(string: PropertyKey): boolean -export default isPropValid +export { default } from '../src' diff --git a/packages/is-prop-valid/types/tslint.json b/packages/is-prop-valid/types/tslint.json index 0f215d5ec..ac5485b6c 100644 --- a/packages/is-prop-valid/types/tslint.json +++ b/packages/is-prop-valid/types/tslint.json @@ -17,6 +17,7 @@ "check-preblock" ], - "no-unnecessary-generics": false + "no-unnecessary-generics": false, + "no-default-import": false } } diff --git a/packages/memoize/types/tests.ts b/packages/memoize/types/tests.ts index 1615284e1..81b32b8ba 100644 --- a/packages/memoize/types/tests.ts +++ b/packages/memoize/types/tests.ts @@ -1,4 +1,4 @@ -import memoize from '../src' +import memoize from '@emotion/memoize' // $ExpectType string[] memoize((arg: string) => [arg])('foo') diff --git a/packages/weak-memoize/types/tests.ts b/packages/weak-memoize/types/tests.ts index 9d54d2849..8daa3243d 100644 --- a/packages/weak-memoize/types/tests.ts +++ b/packages/weak-memoize/types/tests.ts @@ -1,4 +1,4 @@ -import weakMemoize from '../src' +import weakMemoize from '@emotion/weak-memoize' interface Foo { bar: 'xyz'