Skip to content

Commit c24225a

Browse files
authored
Merge pull request #302 from dmiller9911/typings
Moved typings into repo, and updated typings to improve type safety.
2 parents 860fc47 + 6abe537 commit c24225a

9 files changed

Lines changed: 2136 additions & 2 deletions

File tree

no-important.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './typings';

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
],
1010
"main": "lib/index.js",
1111
"module": "es/index.js",
12+
"typings": "typings/index.d.ts",
1213
"scripts": {
13-
"lint": "eslint --fix --cache . && flow check",
14+
"lint": "npm-run-all --parallel lint:*",
15+
"lint:js": "eslint --fix --cache . && flow check",
16+
"lint:ts": "tslint --project tsconfig.json --fix",
1417
"test": "npm run coverage",
1518
"posttest": "npm run lint",
1619
"coverage": "nyc --check-coverage --lines 100 --branches 100 npm run tests",
@@ -47,6 +50,7 @@
4750
"chai": "^3.3.0",
4851
"coveralls": "^2.12.0",
4952
"cross-env": "^5.1.3",
53+
"cross-spawn": "^6.0.4",
5054
"eslint": "^3.7.1",
5155
"eslint-config-standard-react": "^4.2.0",
5256
"eslint-plugin-react": "^6.3.0",
@@ -62,7 +66,9 @@
6266
"rollup-plugin-commonjs": "^8.2.1",
6367
"rollup-plugin-node-resolve": "^3.0.0",
6468
"rollup-plugin-replace": "^2.0.0",
65-
"rollup-plugin-uglify": "^3.0.0"
69+
"rollup-plugin-uglify": "^3.0.0",
70+
"tslint": "^5.9.1",
71+
"typescript": "^2.7.2"
6672
},
6773
"dependencies": {
6874
"asap": "^2.0.3",

tests-ts/aphrodite_test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { css, minify, StyleSheet, StyleSheetServer, StyleSheetTestUtils } from '../typings';
2+
3+
// StyleSheet
4+
const withNumberOrString = StyleSheet.create({
5+
first: {
6+
height: '',
7+
width: 0,
8+
},
9+
});
10+
11+
const withPseudo = StyleSheet.create({
12+
withHover: {
13+
':hover': {
14+
height: '',
15+
width: 0,
16+
},
17+
},
18+
});
19+
20+
const mapValue = new Map();
21+
mapValue.set('position', 'absolute');
22+
mapValue.set('width', 0);
23+
const withMap = StyleSheet.create({ mapValue });
24+
25+
StyleSheet.rehydrate(['']);
26+
27+
StyleSheet.extend([{
28+
selectorHandler: (selector, baseSelector, callback) => {
29+
selector.toLowerCase();
30+
baseSelector.toLowerCase();
31+
callback('').toLowerCase();
32+
return '';
33+
},
34+
}, {
35+
selectorHandler: () => null,
36+
}]);
37+
38+
// css
39+
const withCreateNumberOrString = css(withNumberOrString.first);
40+
const withCreatePseudo = css(withPseudo.withHover);
41+
const withCreateMap = css(withMap.mapValue);
42+
const withObject = css({});
43+
const withUndefinied = css(undefined);
44+
const withNull = css(null);
45+
const withFalse = css(false);
46+
const withArray = css([{}]);
47+
48+
// StyleSheetTestUtils
49+
StyleSheetTestUtils.suppressStyleInjection();
50+
StyleSheetTestUtils.clearBufferAndResumeStyleInjection();
51+
StyleSheetTestUtils.getBufferedStyles()[0].toLowerCase();
52+
53+
// StyleSheetServer
54+
const serverResult = StyleSheetServer.renderStatic(() => '');
55+
serverResult.css.content.toLowerCase();
56+
serverResult.css.renderedClassNames[0].toLowerCase();
57+
serverResult.html.toLowerCase();
58+
59+
// minify
60+
minify(true);
61+
minify(false);

tests/typescript_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {assert} from 'chai';
2+
import spawn from 'cross-spawn'
3+
4+
describe('Typings', () => {
5+
it('compiles successfully', () => {
6+
const typescriptCompilation = spawn.sync('./node_modules/.bin/tsc', [
7+
'-p',
8+
'./tsconfig.json',
9+
]);
10+
const output = typescriptCompilation.stdout.toString();
11+
12+
assert.equal(output, '');
13+
assert.equal(typescriptCompilation.status, 0);
14+
}).timeout(5000);
15+
});

tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": false,
4+
"inlineSources": true,
5+
"module": "commonjs",
6+
"moduleResolution": "node",
7+
"noEmit": true,
8+
"noImplicitAny": true,
9+
"noImplicitReturns": true,
10+
"noUnusedLocals": false,
11+
"noUnusedParameters": false,
12+
"removeComments": false,
13+
"sourceMap": true,
14+
"strictNullChecks": true,
15+
"target": "es6"
16+
},
17+
"include": [
18+
"./tests-ts"
19+
]
20+
}

tslint.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"defaultSeverity": "error",
3+
"extends": [
4+
"tslint:recommended"
5+
],
6+
"jsRules": {},
7+
"rules": {
8+
"indent": [true, "spaces", 4],
9+
"quotemark": [true, "single"]
10+
},
11+
"rulesDirectory": []
12+
}

0 commit comments

Comments
 (0)