Skip to content

Commit

Permalink
Switched to using dtslint from just running tsc --noEmit for typescri…
Browse files Browse the repository at this point in the history
…pt tests.

A few related changes, some as a side-effect of doing so:
* Renamed typings directory to types because this seems to be more standard.
* Renamed emotion.d.ts, etc to index.d.ts because dtslint seems to require this.
* Stopped "build" running before "test:typescript" as this is not actually necessary.
  • Loading branch information
cameron-martin committed Oct 24, 2017
1 parent 8eb316b commit 14543f7
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 89 deletions.
9 changes: 4 additions & 5 deletions packages/emotion-theming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"description": "A CSS-in-JS theming solution, inspired by styled-components",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"types": "typings/emotion-theming.d.ts",
"types": "types/index.d.ts",
"files": [
"src",
"dist"
],
"scripts": {
"build": "npm-run-all clean rollup rollup:umd",
"test:typescript": "tsc --noEmit -p typescript_tests/tsconfig.json",
"pretest:typescript": "npm run build",
"test:typescript": "dtslint types",
"clean": "rimraf dist",
"rollup": "rollup -c ../../rollup.config.js",
"watch": "rollup -c ../../rollup.config.js --watch",
Expand All @@ -39,10 +38,10 @@
"devDependencies": {
"@types/react": "16.0.16",
"cross-env": "^5.0.1",
"dtslint": "^0.2.0",
"prop-types": "^15.5.8",
"rimraf": "^2.6.1",
"rollup": "^0.43.0",
"typescript": "^2.5.3"
"rollup": "^0.43.0"
},
"dependencies": {
"hoist-non-react-statics": "^2.3.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// TypeScript Version: 2.3
import { ComponentClass, SFC } from "react";

export type OptionalThemeProps<Props, Theme> = Props & { theme?: Theme };

export interface ThemeProviderProps<Theme> {
theme: Partial<Theme> | { (theme: Theme): Theme };
theme: Partial<Theme> | ((theme: Theme) => Theme);
}

export type ThemeProviderComponent<Theme> = ComponentClass<ThemeProviderProps<Theme>>;
Expand All @@ -12,9 +13,10 @@ export const ThemeProvider: ThemeProviderComponent<object>;
/**
* Inject theme into component
*/
// tslint:disable-next-line:no-unnecessary-generics
export function withTheme<Props, Theme = {}>(component: ComponentClass<Props> | SFC<Props>): ComponentClass<OptionalThemeProps<Props, Theme>>;

export interface EmotionThemingModule<Theme> {
ThemeProvider: ThemeProviderComponent<Theme>;
withTheme<Props>(component: ComponentClass<Props> | SFC<Props>): ComponentClass<OptionalThemeProps<Props, Theme>>;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import * as emotionTheming from '../';
// tslint:disable-next-line:no-duplicate-imports
import { ThemeProvider, withTheme, EmotionThemingModule } from '../';

const theme = { primary: "green", secondary: "white" };
Expand All @@ -9,7 +10,7 @@ declare class CompC extends React.Component<{ prop: boolean }> { }
/**
* Theme Provider with no type
*/
<ThemeProvider theme={theme} />;
<ThemeProvider theme={theme} />;
<ThemeProvider theme={() => theme} />;

/**
Expand All @@ -21,7 +22,7 @@ const ThemedSFC = withTheme(CompSFC);

const ThemedComp = withTheme(CompC);
<ThemedComp theme={theme} prop />;
<ThemedComp prop />
<ThemedComp prop />;

const { ThemeProvider: TypedThemeProvider, withTheme: typedWithTheme } = emotionTheming as EmotionThemingModule<typeof theme>;

Expand All @@ -31,8 +32,8 @@ const { ThemeProvider: TypedThemeProvider, withTheme: typedWithTheme } = emotion

const TypedThemedSFC = typedWithTheme(ThemedSFC);
<TypedThemedSFC prop />;
<TypedThemedSFC theme={theme} prop/>
<TypedThemedSFC theme={theme} prop/>;

const TypedCompSFC = typedWithTheme(CompSFC);
<TypedCompSFC prop />;
<TypedCompSFC theme={theme} prop />;
<TypedCompSFC theme={theme} prop />;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"strict": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"jsx": "react"
"jsx": "react",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true
},
"include": [
"./*.ts",
Expand Down
6 changes: 6 additions & 0 deletions packages/emotion-theming/types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-relative-import-in-test": false
}
}
9 changes: 4 additions & 5 deletions packages/emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "The Next Generation of CSS-in-JS.",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"types": "typings/emotion.d.ts",
"types": "types/index.d.ts",
"files": [
"src",
"dist",
Expand All @@ -16,8 +16,7 @@
],
"scripts": {
"build": "npm-run-all clean rollup rollup:umd",
"test:typescript": "tsc --noEmit -p typescript_tests/tsconfig.json",
"pretest:typescript": "npm run build",
"test:typescript": "dtslint types",
"clean": "rimraf dist",
"rollup": "rollup -c ../../rollup.config.js",
"watch": "rollup -c ../../rollup.config.js --watch",
Expand All @@ -34,10 +33,10 @@
"babel-cli": "^6.24.1",
"babel-plugin-transform-define": "^1.3.0",
"cross-env": "^5.0.5",
"dtslint": "^0.2.0",
"npm-run-all": "^4.0.2",
"rimraf": "^2.6.1",
"rollup": "^0.43.0",
"typescript": "^2.0.0"
"rollup": "^0.43.0"
},
"author": "Kye Hohenberger",
"homepage": "https://emotion.sh",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
export type Interpolation = string | number | boolean | null | undefined | _Interpolation1 | _Interpolation2 | _Interpolation3;
// TypeScript Version: 2.2
export type Interpolation = string | number | boolean | null | undefined | _Interpolation1 | _Interpolation2 | (() => Interpolation);

// HACK: See https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
interface _Interpolation1 extends Record<string, Interpolation> {}
interface _Interpolation2 extends Array<Interpolation> {}
interface _Interpolation3 {
(): Interpolation;
}
export interface _Interpolation1 extends Record<string, Interpolation> {}
export interface _Interpolation2 extends Array<Interpolation> {}

export type CreateStyles<TRet> = ((...values: Interpolation[]) => TRet)
& ((strings: TemplateStringsArray, ...vars: Interpolation[]) => TRet);

export interface StylisUse {
// TODO: Make this more precise than just Function
(plugin: Function | Function[] | null): StylisUse;
}
// TODO: Make this more precise than just Function
// tslint:disable-next-line:ban-types
export type StylisUse = (plugin: Function | Function[] | null) => StylisUse;

export interface StyleSheet {
inject(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
hydrate,
cx
} from '../';
// tslint:disable-next-line:no-implicit-dependencies
import React from 'react';

sheet.speedy(true);
Expand Down Expand Up @@ -50,7 +51,7 @@ css([
{ position: false },
{ width: 100 }
]
])
]);

css(
{ display: 'none' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"strict": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"jsx": "react"
"jsx": "react",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true
},
"include": [
"./*.ts",
Expand Down
6 changes: 6 additions & 0 deletions packages/emotion/types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-relative-import-in-test": false
}
}
9 changes: 4 additions & 5 deletions packages/react-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "The Next Generation of CSS-in-JS, for React projects.",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"types": "typings/react-emotion.d.ts",
"types": "types/index.d.ts",
"files": [
"src",
"dist",
Expand All @@ -13,8 +13,7 @@
],
"scripts": {
"build": "npm-run-all clean rollup rollup:umd",
"test:typescript": "tsc --noEmit -p typescript_tests/tsconfig.json",
"pretest:typescript": "npm run build",
"test:typescript": "dtslint types",
"clean": "rimraf dist",
"rollup": "rollup -c ../../rollup.config.js",
"watch": "rollup -c ../../rollup.config.js --watch",
Expand All @@ -30,11 +29,11 @@
"devDependencies": {
"@types/react": "16.0.16",
"cross-env": "^5.0.5",
"dtslint": "^0.2.0",
"emotion": "^8.0.9",
"npm-run-all": "^4.0.2",
"rimraf": "^2.6.1",
"rollup": "^0.43.0",
"typescript": "^2.0.0"
"rollup": "^0.43.0"
},
"author": "Kye Hohenberger",
"homepage": "https://github.com/tkh44/emotion#readme",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
import { StatelessComponent, ComponentClass, CSSProperties } from 'react'
import { Interpolation as EmotionInterpolation } from 'emotion'
// TypeScript Version: 2.3
// tslint:disable-next-line:no-implicit-dependencies
import { StatelessComponent, ComponentClass, CSSProperties } from 'react';
import { Interpolation as EmotionInterpolation } from 'emotion';

export * from 'emotion'
export * from 'emotion';

export type InterpolationFn<Props = {}> =
(props: Props) =>
| EmotionInterpolation
| InterpolationFn<Props>
| InterpolationFn<Props>;

export type InterpolationTypes<Props = {}> =
| InterpolationFn<Props>
| EmotionInterpolation
| EmotionInterpolation;

export type Interpolation<Props = {}> =
| InterpolationTypes<Props>
| InterpolationTypes<Props>[]
| Array<InterpolationTypes<Props>>;

export interface Options {
string?: string,
string?: string;
}

type Component<Props> =
| ComponentClass<Props>
| StatelessComponent<Props>
| StatelessComponent<Props>;

export type ThemedProps<Props, Theme> = Props & {
theme: Theme,
}
};

type ElementProps<Tag extends keyof JSX.IntrinsicElements> =
& JSX.IntrinsicElements[Tag]
& { innerRef?: JSX.IntrinsicElements[Tag]['ref'] }
& { innerRef?: JSX.IntrinsicElements[Tag]['ref'] };

export interface StyledComponent<Props, Theme, IntrinsicProps>
extends
ComponentClass<Props & IntrinsicProps>,
StatelessComponent<Props & IntrinsicProps>
{
StatelessComponent<Props & IntrinsicProps> {
withComponent<Tag extends keyof JSX.IntrinsicElements>(tag: Tag):
StyledComponent<Props, Theme, ElementProps<Tag>>
StyledComponent<Props, Theme, ElementProps<Tag>>;

withComponent(component: Component<Props>):
StyledComponent<Props, Theme, {}>
StyledComponent<Props, Theme, {}>;

displayName: string
displayName: string;

__emotion_styles: string[]
__emotion_base: string | Component<Props & IntrinsicProps>
__emotion_real: ThemedReactEmotionInterface<Theme>
__emotion_styles: string[];
__emotion_base: string | Component<Props & IntrinsicProps>;
__emotion_real: ThemedReactEmotionInterface<Theme>;
}

export type ObjectStyleAttributes =
| CSSProperties
| { [key: string]: ObjectStyleAttributes }
| { [key: string]: ObjectStyleAttributes };

export interface CreateStyled<Props, Theme, IntrinsicProps> {
// overload for template string as styles
(
strings: TemplateStringsArray,
...vars: Interpolation<ThemedProps<Props & IntrinsicProps, Theme>>[],
): StyledComponent<Props, Theme, IntrinsicProps>
...vars: Array<Interpolation<ThemedProps<Props & IntrinsicProps, Theme>>>,
): StyledComponent<Props, Theme, IntrinsicProps>;

// overload for object as styles
(
...styles: (
...styles: Array<
| ObjectStyleAttributes
| ((props: ThemedProps<Props & IntrinsicProps, Theme>) => ObjectStyleAttributes)
)[]
): StyledComponent<Props, Theme, IntrinsicProps>
>
): StyledComponent<Props, Theme, IntrinsicProps>;
}

// TODO: find a way to reuse CreateStyled here
Expand All @@ -77,15 +78,15 @@ type ShorthandsFactories<Theme> = {
// overload for template string as styles
<Props = {}>(
strings: TemplateStringsArray,
...vars: Interpolation<ThemedProps<Props & JSX.IntrinsicElements[Tag], Theme>>[],
...vars: Array<Interpolation<ThemedProps<Props & JSX.IntrinsicElements[Tag], Theme>>>,
): StyledComponent<Props, Theme, ElementProps<Tag>>

// overload for object as styles
<Props = {}>(
...styles: (
...styles: Array<
| ObjectStyleAttributes
| ((props: ThemedProps<Props & JSX.IntrinsicElements[Tag], Theme>) => ObjectStyleAttributes)
)[]
>
): StyledComponent<Props, Theme, ElementProps<Tag>>
};
};
Expand All @@ -95,20 +96,19 @@ export interface ThemedReactEmotionInterface<Theme> extends ShorthandsFactories<
<Props, Tag extends keyof JSX.IntrinsicElements>(
tag: Tag,
options?: Options,
): CreateStyled<Props, Theme, ElementProps<Tag>>
// tslint:disable-next-line:no-unnecessary-generics
): CreateStyled<Props, Theme, ElementProps<Tag>>;

// overload for component
<Props>(
component: Component<Props>,
options?: Options,
): CreateStyled<Props, Theme, {}>
): CreateStyled<Props, Theme, {}>;
}

export interface ThemedReactEmotionModule<Theme> {
default: ThemedReactEmotionInterface<Theme>
default: ThemedReactEmotionInterface<Theme>;
}

declare const styled: ThemedReactEmotionInterface<any>
export default styled


declare const styled: ThemedReactEmotionInterface<any>;
export default styled;
Loading

0 comments on commit 14543f7

Please sign in to comment.