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

WIP: Add typescript typings #37

Closed
Closed
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "4.1.2",
"description": "high performance css-in-js",
"main": "lib/index.js",
"typings": "styled.d.ts",
"files": [
"babel.js",
"src",
Expand All @@ -29,6 +30,7 @@
},
"dependencies": {
"babel-plugin-syntax-jsx": "^6.18.0",
"@types/react": "^15.0.33",
"styled-components": "2.0.0",
"touch": "^1.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/styled.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { css } from './index'

export default function (tag, cls, vars = [], content) {
export default function (tag, cls = '', vars = [], content) {
if (!tag) {
throw new Error(
'You are trying to create a styled element with an undefined component.\nYou may have forgotten to import it.'
Expand Down
57 changes: 57 additions & 0 deletions styled.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
declare module "emotion" {
export const inserted: Record<string, boolean | undefined>;

export type InputValue = string | number;

export function values(cls: string, vars: InputValue[]): string;

export function flush(): void;

export function css(
cls: string,
content: TemplateStringsArray,
...vars: InputValue[],
): string;

export function injectGlobal(src: string[]): void;
export const fontFace = injectGlobal;

export function keyframes(kfm: string, src: string[]): string;

export function hydrate(ids: string[]): void;
}

declare module "emotion/styled" {
import { ComponentClass, StatelessComponent, HTMLProps } from "react";

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

export type InterpolationValue = string | number;

export type Tagged<P> = (
content: TemplateStringsArray,
...vars: InterpolationValue[],
) => Component<P>;

export default function<P>(tag: Component<P>): Tagged<P>;
export default function(
tag: keyof HTMLElementTagNameMap,
cls?: string,
): Tagged<HTMLProps<P>>;
}

declare module "emotion/server" {
export interface Rule {
cssText: string;
}

export interface Result {
html: string;
ids: Record<string, boolean | undefined>;
css: string;
rules: Rule[];
}

export function renderStatic(fn: () => string | undefined): Result;
export function renderStaticOptimized(fn: () => string | undefined): Result;
}