Skip to content

Commit

Permalink
Migrate @emotion/is-prop-valid to TypeScript (#2432)
Browse files Browse the repository at this point in the history
* [is-prop-valid] Convert to TypeScript

* Add changeset

* tweak some minor things

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
sarayourfriend and Andarist committed Aug 14, 2021
1 parent fc4d27c commit a1e881b
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-yaks-flow.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 2 additions & 3 deletions packages/is-prop-valid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 3 additions & 0 deletions packages/is-prop-valid/src/props.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions packages/is-prop-valid/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 2.1

declare function isPropValid(string: PropertyKey): boolean
export default isPropValid
export { default } from '../src'
3 changes: 2 additions & 1 deletion packages/is-prop-valid/types/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"check-preblock"
],

"no-unnecessary-generics": false
"no-unnecessary-generics": false,
"no-default-import": false
}
}
2 changes: 1 addition & 1 deletion packages/memoize/types/tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import memoize from '../src'
import memoize from '@emotion/memoize'

// $ExpectType string[]
memoize((arg: string) => [arg])('foo')
Expand Down
2 changes: 1 addition & 1 deletion packages/weak-memoize/types/tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import weakMemoize from '../src'
import weakMemoize from '@emotion/weak-memoize'

interface Foo {
bar: 'xyz'
Expand Down

0 comments on commit a1e881b

Please sign in to comment.