Skip to content

Commit

Permalink
Fix TS 4.7 error related to isPropValid
Browse files Browse the repository at this point in the history
  • Loading branch information
srmagura committed Apr 24, 2022
1 parent 9ca22c6 commit 6c652d9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
23 changes: 8 additions & 15 deletions packages/css/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { CSSInterpolation } from '@emotion/serialize'

export declare const flush: () => void,
hydrate: (ids: string[]) => void,
cx: (...classNames: import('./create-instance').ClassNamesArg[]) => string,
Expand All @@ -7,25 +9,16 @@ export declare const flush: () => void,
className: string
) => string,
injectGlobal: {
(
template: TemplateStringsArray,
...args: import('@emotion/serialize').CSSInterpolation[]
): void
(...args: import('@emotion/serialize').CSSInterpolation[]): void
(template: TemplateStringsArray, ...args: CSSInterpolation[]): void
(...args: CSSInterpolation[]): void
},
keyframes: {
(
template: TemplateStringsArray,
...args: import('@emotion/serialize').CSSInterpolation[]
): string
(...args: import('@emotion/serialize').CSSInterpolation[]): string
(template: TemplateStringsArray, ...args: CSSInterpolation[]): string
(...args: CSSInterpolation[]): string
},
css: {
(
template: TemplateStringsArray,
...args: import('@emotion/serialize').CSSInterpolation[]
): string
(...args: import('@emotion/serialize').CSSInterpolation[]): string
(template: TemplateStringsArray, ...args: CSSInterpolation[]): string
(...args: CSSInterpolation[]): string
},
sheet: import('./create-instance').CSSStyleSheet,
cache: import('@emotion/utils/src/types').EmotionCache
2 changes: 0 additions & 2 deletions packages/is-prop-valid/src/index.d.ts

This file was deleted.

11 changes: 6 additions & 5 deletions packages/is-prop-valid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ declare const codegen: { require: (path: string) => any }
const reactPropsRegex: RegExp = codegen.require('./props')

// https://esbench.com/bench/5bfee68a4cd7e6009ef61d23
const isPropValid = /* #__PURE__ */ memoize(
const isPropValid = /* #__PURE__ */ memoize<PropertyKey, boolean>(
prop =>
reactPropsRegex.test(prop) ||
(prop.charCodeAt(0) === 111 /* o */ &&
prop.charCodeAt(1) === 110 /* n */ &&
prop.charCodeAt(2) < 91) /* Z+1 */
typeof prop === 'string' &&
(reactPropsRegex.test(prop) ||
(prop.charCodeAt(0) === 111 /* o */ &&
prop.charCodeAt(1) === 110 /* n */ &&
prop.charCodeAt(2) < 91)) /* Z+1 */
)

export default isPropValid
1 change: 0 additions & 1 deletion packages/memoize/src/index.d.ts

This file was deleted.

8 changes: 5 additions & 3 deletions packages/memoize/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export default function memoize<V>(fn: (arg: string) => V): (arg: string) => V {
const cache: Record<string, V> = Object.create(null)
export default function memoize<K extends PropertyKey, V>(
fn: (arg: K) => V
): (arg: K) => V {
const cache: Record<K, V> = Object.create(null)

return (arg: string) => {
return (arg: K) => {
if (cache[arg] === undefined) cache[arg] = fn(arg)
return cache[arg]
}
Expand Down
1 change: 0 additions & 1 deletion packages/memoize/types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import memoize from '@emotion/memoize'
// $ExpectType string[]
memoize((arg: string) => [arg])('foo')

// $ExpectError
memoize((arg: number) => [arg])

0 comments on commit 6c652d9

Please sign in to comment.