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

[is-prop-valid] Convert to TypeScript #2432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense 👍 making this go through something like ts-node would be overengineered, I'm OK with this being a JS file

*/
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