Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Ginnivan committed Sep 24, 2019
1 parent e2718b1 commit c88a1f4
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 93 deletions.
3 changes: 3 additions & 0 deletions packages/babel-plugin-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"lib",
"dist"
],
"scripts": {
"test:typescript": "exit 0"
},
"dependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@emotion/hash": "0.7.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-plugin-jsx-pragmatic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"module": "dist/babel-plugin-jsx-pragmatic.esm.js",
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/master/packages/babel-plugin-jsx-pragmatic",
"scripts": {
"test:typescript": "exit 0"
},
"dependencies": {
"@babel/plugin-syntax-jsx": "^7.2.0"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-preset-css-prop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"module": "dist/babel-preset-css-prop.esm.js",
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/master/packages/babel-preset-css-prop",
"scripts": {
"test:typescript": "exit 0"
},
"dependencies": {
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/runtime": "^7.5.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-emotion/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 2.8
// TypeScript Version: 2.9

import { EmotionCache, Options } from '@emotion/cache'
import { Interpolation } from '@emotion/serialize'
Expand Down
2 changes: 1 addition & 1 deletion packages/create-emotion/types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import createEmotion from 'create-emotion'
const emotion0 = createEmotion()
// $ExpectType Emotion
const emotion1 = createEmotion({
container: document.head !== null ? document.head : undefined,
container: document.head,
nonce: 'fasefw'
})

Expand Down
5 changes: 3 additions & 2 deletions packages/create-emotion/types/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"check-typecast",
"check-type-operator",
"check-preblock"
]
],
"no-null-undefined-union": false
}
}
}
8 changes: 0 additions & 8 deletions packages/css/types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,3 @@ css`
position: relative;
top: ${'20px'};
`

// $ExpectError
css(() => 'height: 300px;')
// $ExpectError
css`
position: relative;
flexgrow: ${() => 20};
`
9 changes: 0 additions & 9 deletions packages/emotion-theming/types/helper.d.ts

This file was deleted.

31 changes: 12 additions & 19 deletions packages/emotion-theming/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import * as React from 'react'
import {
StyledComponent,
StyledOptions,
CreateStyledComponent
CreateStyledComponent,
StyledTags
} from '@emotion/styled'
import { PropsOf } from '@emotion/styled-base'

export interface ThemeProviderProps<Theme> {
theme: Partial<Theme> | ((outerTheme: Theme) => Theme)
Expand All @@ -20,29 +22,20 @@ export function ThemeProvider<Theme>(

export function useTheme<Theme>(): Theme

export function withTheme<P extends object>(
component: React.ComponentType<P & { theme: any }>
): // Return type needs to have an optional theme so it is composible
React.FC<Omit<P, 'theme'> & { theme?: any }>

export interface EmotionTheming<Theme> {
ThemeProvider(props: ThemeProviderProps<Theme>): React.ReactElement
withTheme<P extends object>(
component: React.ComponentType<P & { theme: Theme }>
): React.FC<Omit<P, 'theme'> & { theme?: any }>
export interface withTheme<Theme> {
<C extends React.ReactType<any>>(component: C): React.FC<
Omit<PropsOf<C>, 'theme'> & { theme?: Theme }
>
}

export const withTheme: withTheme<any>

/**
* @desc
* This function accepts `InnerProps`/`Tag` to infer the type of `tag`,
* and accepts `ExtraProps` for user who use string style
* to be able to declare extra props without using
* `` styled('button')<ExtraProps>`...` ``, which does not supported in
* styled-component VSCode extension.
* If your tool support syntax highlighting for `` styled('button')<ExtraProps>`...` ``
* it could be more efficient.
* Themed version of CreateStyled
*/
export interface CreateThemedStyled<Theme extends object> {
export interface CreateThemedStyled<Theme extends object>
extends StyledTags<{ theme: Theme }> {
<Props extends object, ExtraProps = {}>(
tag: React.ComponentType<Props>,
options?: StyledOptions
Expand Down
4 changes: 2 additions & 2 deletions packages/emotion-theming/types/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ interface Props {
prop: boolean
theme: Theme
}
declare const CompSFC: React.SFC<Props>
declare const CompSFC: React.FC<Props>
declare class CompC extends React.Component<Props> {}

const WrappedCompC = withTheme<typeof CompC>(CompC)
const WrappedCompC = withTheme(CompC)
;<ThemeProvider theme={theme}>{WrappedCompC}</ThemeProvider>
;<ThemeProvider theme={() => theme} />
;<ThemeProvider theme={(outerTheme: Theme) => ({ ...outerTheme, ...theme })} />
Expand Down
1 change: 0 additions & 1 deletion packages/serialize/types/helper.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/serialize/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface ObjectInterpolation<MP>
extends CSSPropertiesWithMultiValues,
CSSPseudos<MP>,
CSSOthersObject<MP> {}

export interface FunctionInterpolation<MP> {
(mergedProps: MP):
| null
Expand Down
2 changes: 1 addition & 1 deletion packages/sheet/types/tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options, StyleSheet } from '@emotion/sheet'
import { StyleSheet } from '@emotion/sheet'

new StyleSheet({
key: 'abc',
Expand Down
3 changes: 0 additions & 3 deletions packages/styled-base/types/helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ import * as React from 'react'
export type PropsOf<
C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>
> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithRef<C>>

export type Omit<T, U> = T extends any ? Pick<T, Exclude<keyof T, U>> : never
export type Overwrapped<T, U> = Pick<T, Extract<keyof T, keyof U>>
46 changes: 25 additions & 21 deletions packages/styled-base/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import { ComponentSelector, Interpolation } from '@emotion/serialize'
import * as React from 'react'
import { PropsOf } from './helper'

export {
ArrayInterpolation,
Expand All @@ -22,16 +23,16 @@ export {
ObjectInterpolation
} from '@emotion/serialize'

export { ComponentSelector, Interpolation }
export { ComponentSelector, Interpolation, PropsOf }

export interface StyledOptions {
label?: string
shouldForwardProp?(propName: string): boolean
target?: string
}

export interface StyledComponent<InnerProps, StyleProps>
extends React.SFC<InnerProps & StyleProps>,
export interface StyledComponent<ComponentProps, StyleProps>
extends React.FC<ComponentProps & StyleProps>,
ComponentSelector {
/**
* @desc this method is type-unsafe
Expand All @@ -44,35 +45,38 @@ export interface StyledComponent<InnerProps, StyleProps>
): StyledComponent<Props, StyleProps>
}

type ReactClassPropKeys = keyof React.ClassAttributes<any>

export interface CreateStyledComponent<InnerProps, ExtraProps> {
export interface CreateStyledComponent<Props, ExtraProps> {
<StyleProps extends object>(
...styles: Array<Interpolation<InnerProps & StyleProps & ExtraProps>>
): StyledComponent<InnerProps, StyleProps>
...styles: Array<Interpolation<Props & StyleProps & ExtraProps>>
): StyledComponent<Props, StyleProps>
<StyleProps extends object>(
template: TemplateStringsArray,
...styles: Array<Interpolation<InnerProps & StyleProps & ExtraProps>>
): StyledComponent<InnerProps, StyleProps>
...styles: Array<Interpolation<Props & StyleProps & ExtraProps>>
): StyledComponent<Props, StyleProps>
}

// We have opted to using the props as the generic parameter because it improves
// inference and allows us to put contraints on the Props.

/**
* @desc
* This function accepts `InnerProps`/`Tag` to infer the type of `tag`,
* and accepts `ExtraProps` for user who use string style
* to be able to declare extra props without using
* `` styled('button')<ExtraProps>`...` ``, which does not supported in
* styled-component VSCode extension.
* If your tool support syntax highlighting for `` styled('button')<ExtraProps>`...` ``
* it could be more efficient.
* This function accepts a React component or tag ('div', 'a' etc).
*
* This function does not support React default props defaultProps, use the following syntax to fix
* styled<PropsOf<MyComponent>>(MyComponent)({ width: 100 })
*
* @example styled(MyComponent)({ width: 100 })
* @example styled(MyComponent)(myComponentProps => ({ width: myComponentProps.width })
* @example styled('div')({ width: 100 })
* @example styled('div')<Props>(props => ({ width: props.width })
*/
export interface CreateStyled {
<Props extends object, ExtraProps = {}>(
component: React.ComponentType<Props>,
<P extends {}, ExtraProps = { theme: any }>(
component: React.ReactType<P>,
options?: StyledOptions
): CreateStyledComponent<Props, ExtraProps>
): CreateStyledComponent<P, ExtraProps>

<Tag extends keyof JSX.IntrinsicElements, ExtraProps = {}>(
<Tag extends keyof JSX.IntrinsicElements, ExtraProps = { theme: any }>(
tag: Tag,
options?: StyledOptions
): CreateStyledComponent<JSX.IntrinsicElements[Tag], ExtraProps>
Expand Down
57 changes: 34 additions & 23 deletions packages/styled-base/types/tests.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react'
import styled from '@emotion/styled-base'
import styled, { PropsOf } from '@emotion/styled-base'

// tslint:disable-next-line: interface-over-type-literal
type ReactClassProps0 = {
readonly column: boolean
}
declare class ReactClassComponent0 extends React.Component<ReactClassProps0> {}
class ReactClassComponent0 extends React.Component<ReactClassProps0> {}

interface ReactClassProps1 {
readonly value: string
Expand Down Expand Up @@ -82,22 +82,15 @@ const Canvas1 = styled('canvas', {
interface PrimaryProps {
readonly primary: string
}
/**
* @desc
* This function accepts `InnerProps`/`Tag` to infer the type of `tag`,
* and accepts `ExtraProps` for user who use string style
* to be able to declare extra props without using
* `` styled('button')<ExtraProps>`...` ``, which does not supported in
* styled-component VSCode extension.
* If your tool support syntax highlighting for `` styled('button')<ExtraProps>`...` ``
* it could be more efficient.
*/
const Button2 = styled<'button', PrimaryProps>('button')`

const Button2 = styled('button')<PrimaryProps>`
fontsize: ${5}px;
color: ${props => props.primary};
`
const Button3 = styled<'button', PrimaryProps>('button')(props => ({
color: props.primary
const Button3 = styled('button')<PrimaryProps>(props => ({
color: props.primary,
// Verify we get access to intrinsic props
display: props.hidden ? 'none' : undefined
}))
;<div>
<Button2 primary="blue" />
Expand All @@ -116,15 +109,13 @@ const Button3 = styled<'button', PrimaryProps>('button')(props => ({
// $ExpectError
;<Button3 type="button" />

const Button4 = styled<typeof ReactClassComponent0, PrimaryProps>(
ReactClassComponent0
)`
backgroundColor: ${props => props.theme.backColor}
const Button4 = styled(ReactClassComponent0)<PrimaryProps>`
backgroundcolor: ${props => props.theme.backColor};
fontSize: ${5}px;
color: ${props => props.primary}
fontsize: ${5}px;
color: ${props => props.primary};
`
const Button5 = styled<typeof ReactSFC0, PrimaryProps>(ReactSFC0)(props => ({
const Button5 = styled(ReactSFC0)<PrimaryProps>(props => ({
color: props.primary
}))
;<div>
Expand Down Expand Up @@ -203,11 +194,28 @@ styled(ReactSFC2)<ReactSFCProps1>()
Container0.withComponent(ReactClassComponent2)
Container3.withComponent(ReactClassComponent2)

const StyledClass0 = styled(ReactClassComponent0)({})
const ForwardRefCheckStyled = styled(
React.forwardRef(
(props: ReactClassProps0, ref: React.Ref<HTMLDivElement>) => {
return <div ref={ref} />
}
)
)({})

// Expose ref only when inner component is forwarding refs
;<ForwardRefCheckStyled column={true} ref={React.createRef<HTMLDivElement>()} />

const StyledClass0 = styled<PropsOf<typeof ReactClassComponent0>>(
ReactClassComponent0
)({})
const StyledClass01 = styled(ReactClassComponent0)<
PropsOf<typeof ReactClassComponent0>
>({})
declare const ref0_0: (element: ReactClassComponent0 | null) => void
declare const ref0_1: (element: ReactClassComponent1 | null) => void
declare const ref0_2: (element: HTMLDivElement | null) => void
;<StyledClass0 column={true} ref={ref0_0} />
;<StyledClass01 column={true} ref={ref0_0} />
// $ExpectError
;<StyledClass0 column={true} ref={ref0_1} />
// $ExpectError
Expand All @@ -217,6 +225,7 @@ const StyledClass1 = StyledClass0.withComponent(ReactClassComponent1)
declare const ref1_0: (element: ReactClassComponent1 | null) => void
declare const ref1_1: (element: ReactClassComponent0 | null) => void
declare const ref1_2: (element: HTMLDivElement | null) => void
// $ExpectError
;<StyledClass1 column={true} value="" ref={ref1_0} />
// $ExpectError
;<StyledClass1 column={true} value="" ref={ref1_1} />
Expand All @@ -227,6 +236,7 @@ const StyledClass2 = StyledClass0.withComponent('div')
declare const ref2_0: (element: HTMLDivElement | null) => void
declare const ref2_1: (element: ReactClassComponent0 | null) => void
declare const ref2_2: (element: ReactClassComponent1 | null) => void
// $ExpectError
;<StyledClass2 column={true} ref={ref2_0} />
// $ExpectError
;<StyledClass2 column={true} ref={ref2_1} />
Expand All @@ -237,6 +247,7 @@ const StyledClass3 = StyledClass1.withComponent('label')
declare const ref3_0: (element: HTMLLabelElement | null) => void
declare const ref3_1: (element: ReactClassComponent0 | null) => void
declare const ref3_2: (element: HTMLDivElement | null) => void
// $ExpectError
;<StyledClass3 column={true} ref={ref3_0} />
// $ExpectError
;<StyledClass3 column={true} ref={ref3_1} />
Expand Down
4 changes: 2 additions & 2 deletions packages/styled/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export {
} from '@emotion/styled-base'

export type StyledTags<ExtraProps extends object = {}> = {
[tag in keyof JSX.IntrinsicElements]: CreateStyledComponent<
JSX.IntrinsicElements[tag],
[Tag in keyof JSX.IntrinsicElements]: CreateStyledComponent<
JSX.IntrinsicElements[Tag],
ExtraProps
>
}
Expand Down

0 comments on commit c88a1f4

Please sign in to comment.