Skip to content

Commit cd2dc4f

Browse files
mgroenhoffemmatown
authored andcommitted
Add Typescript definitions for 'create-emotion-server' and 'emotion-server' (#692)
* Add Typescript definitions for 'create-emotion-server' and 'emotion-server' * Update yarn.lock * Add missing line feed to end of tslint.json files
1 parent 8a45c95 commit cd2dc4f

File tree

14 files changed

+136
-9
lines changed

14 files changed

+136
-9
lines changed

packages/create-emotion-server/package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@
33
"version": "9.1.3",
44
"description": "SSR and style extraction tooling for emotion, The Next Generation of CSS-in-JS.",
55
"main": "lib/index.js",
6+
"types": "types/index.d.ts",
67
"files": [
78
"src",
8-
"lib"
9+
"lib",
10+
"types"
911
],
1012
"scripts": {
1113
"build": "npm-run-all clean babel",
1214
"babel": "babel src -d lib",
13-
"watch": "babel src -d lib --watch",
14-
"clean": "rimraf lib"
15+
"clean": "rimraf lib",
16+
"test:typescript": "dtslint types",
17+
"watch": "babel src -d lib --watch"
1518
},
1619
"dependencies": {
1720
"html-tokenize": "^2.0.0",
1821
"multipipe": "^1.0.2",
1922
"through": "^2.3.8"
2023
},
2124
"devDependencies": {
25+
"@types/node": "*",
2226
"babel-cli": "^6.24.1",
27+
"dtslint": "^0.3.0",
2328
"emotion": "^9.1.3",
2429
"npm-run-all": "^4.0.2",
2530
"react-emotion": "^9.1.3",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference types="node" />
2+
// TypeScript Version: 2.3
3+
4+
import { Emotion } from 'create-emotion';
5+
6+
export interface EmotionServer {
7+
extractCritical(html: string): { html: string; ids: string[]; css: string; };
8+
renderStylesToString(html: string): string;
9+
renderStylesToNodeStream(): NodeJS.ReadWriteStream;
10+
}
11+
12+
export default function createEmotionServer(emotion: Emotion): EmotionServer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Emotion } from 'create-emotion';
2+
3+
import createEmotionServer from '../';
4+
5+
declare const emotion: Emotion;
6+
7+
const emotionServer = createEmotionServer(emotion);
8+
9+
const { html, css, ids } = emotionServer.extractCritical("<div></div>");
10+
11+
emotionServer.renderStylesToString("<div></div>");
12+
13+
declare const stream: NodeJS.ReadableStream;
14+
15+
stream.pipe(emotionServer.renderStylesToNodeStream());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "../",
4+
"forceConsistentCasingInFileNames": true,
5+
"jsx": "react",
6+
"lib": [
7+
"es6"
8+
],
9+
"module": "commonjs",
10+
"noEmit": true,
11+
"noImplicitAny": true,
12+
"noImplicitThis": true,
13+
"strict": true,
14+
"strictNullChecks": true,
15+
"strictFunctionTypes": true,
16+
"target": "es5",
17+
"typeRoots": [
18+
"../"
19+
],
20+
"types": []
21+
},
22+
"include": [
23+
"./*.ts",
24+
"./*.tsx"
25+
]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"no-relative-import-in-test": false
5+
}
6+
}

packages/emotion-server/package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"version": "9.1.3",
44
"description": "Extract and inline critical css with emotion for server side rendering.",
55
"main": "lib/index.js",
6+
"types": "types/index.d.ts",
67
"files": [
78
"src",
8-
"lib"
9+
"lib",
10+
"types"
911
],
1012
"scripts": {
1113
"build": "npm-run-all clean babel",
1214
"babel": "babel src -d lib",
13-
"watch": "babel src -d lib --watch",
14-
"clean": "rimraf lib"
15+
"clean": "rimraf lib",
16+
"test:typescript": "dtslint types",
17+
"watch": "babel src -d lib --watch"
1518
},
1619
"dependencies": {
1720
"create-emotion-server": "^9.1.3"
@@ -20,8 +23,10 @@
2023
"emotion": "^9.1.3"
2124
},
2225
"devDependencies": {
26+
"@types/react-dom": "16.0.5",
2327
"babel-cli": "^6.24.1",
2428
"babel-plugin-emotion": "^9.1.2",
29+
"dtslint": "^0.3.0",
2530
"emotion": "^9.1.3",
2631
"npm-run-all": "^4.0.2",
2732
"react-emotion": "^9.1.3",
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// TypeScript Version: 2.3
2+
3+
import { EmotionServer } from 'create-emotion-server';
4+
5+
export const renderStylesToString: EmotionServer["renderStylesToString"];
6+
export const renderStylesToNodeStream: EmotionServer["renderStylesToNodeStream"];
7+
export const extractCritical: EmotionServer["extractCritical"];
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import { renderToNodeStream, renderToString } from 'react-dom/server';
3+
import { extractCritical, renderStylesToNodeStream, renderStylesToString } from '../';
4+
5+
declare const element: React.ReactElement<any>;
6+
7+
const { html, css, ids } = extractCritical(renderToString(element));
8+
9+
renderStylesToString(renderToString(element));
10+
11+
renderToNodeStream(element).pipe(renderStylesToNodeStream());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"baseUrl": "../",
5+
"forceConsistentCasingInFileNames": true,
6+
"jsx": "react",
7+
"lib": [
8+
"es6"
9+
],
10+
"module": "commonjs",
11+
"noEmit": true,
12+
"noImplicitAny": true,
13+
"noImplicitThis": true,
14+
"strict": true,
15+
"strictNullChecks": true,
16+
"strictFunctionTypes": true,
17+
"target": "es5",
18+
"typeRoots": [
19+
"../"
20+
],
21+
"types": []
22+
},
23+
"include": [
24+
"./*.ts",
25+
"./*.tsx"
26+
]
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"no-relative-import-in-test": false
5+
}
6+
}

packages/emotion-theming/types/tslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"rules": {
44
"no-relative-import-in-test": false
55
}
6-
}
6+
}

packages/emotion/types/tslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"rules": {
44
"no-relative-import-in-test": false
55
}
6-
}
6+
}

packages/react-emotion/types/tslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"rules": {
44
"no-relative-import-in-test": false
55
}
6-
}
6+
}

yarn.lock

+7
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,13 @@
923923
version "1.6.2"
924924
resolved "https://registry.yarnpkg.com/@types/parsimmon/-/parsimmon-1.6.2.tgz#2ecb8424e06fd8db78b6f697b635064dfa355441"
925925

926+
927+
version "16.0.5"
928+
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.0.5.tgz#a757457662e3819409229e8f86795ff37b371f96"
929+
dependencies:
930+
"@types/node" "*"
931+
"@types/react" "*"
932+
926933
"@types/react-router-dom@^4.2.2":
927934
version "4.2.6"
928935
resolved "https://registry.yarnpkg.com/@types/react-router-dom/-/react-router-dom-4.2.6.tgz#9f7eb3c0e6661a9607d878ff8675cc4ea95cd276"

0 commit comments

Comments
 (0)