Skip to content

Commit 720254f

Browse files
committed
feat(TypeScript): TS module defintions
1 parent 162cc05 commit 720254f

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

package.json

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,59 +42,45 @@
4242
"standard-version": "^4.2.0",
4343
"storybook-readme": "^3.1.1",
4444
"style-loader": "^0.19.0",
45+
"typescript": "^2.6.2",
4546
"validate-commit-msg": "^2.14.0"
4647
},
47-
"files": [
48-
"lib"
49-
],
48+
"files": ["lib", "types/index.d.ts"],
49+
"types": "types/index.d.ts",
5050
"homepage": "https://github.com/researchgate/react-intersection-observer#readme",
51-
"keywords": [
52-
"Intersection",
53-
"Observer",
54-
"react",
55-
"component",
56-
"viewport",
57-
"visible",
58-
"invisible",
59-
"researchgate"
60-
],
51+
"keywords": ["Intersection", "Observer", "react", "component", "viewport", "visible", "invisible", "researchgate"],
6152
"license": "MIT",
6253
"lint-staged": {
63-
"{src,docs/docs}/**/*.js": [
64-
"eslint --fix",
65-
"git add"
66-
]
54+
"{src,docs/docs}/**/*.js": ["eslint --fix", "git add"]
6755
},
6856
"main": "lib/js/index.js",
6957
"module": "lib/es/index.js",
7058
"peerDependencies": {
71-
"react": "^15.4.0 || ^16.0.0",
72-
"react-dom": "^15.4.0 || ^16.0.0"
59+
"react": ">=15",
60+
"react-dom": ">=15"
7361
},
7462
"repository": {
7563
"type": "git",
7664
"url": "https://github.com/researchgate/react-intersection-observer"
7765
},
7866
"jest": {
7967
"rootDir": "src",
80-
"testMatch": [
81-
"**/__tests__/**/*.spec.js"
82-
],
83-
"setupFiles": [
84-
"raf/polyfill"
85-
]
68+
"testMatch": ["**/__tests__/**/*.spec.js"],
69+
"setupFiles": ["raf/polyfill"]
8670
},
8771
"scripts": {
8872
"build": "yarn build:js && yarn build:es",
89-
"build:js": "cross-env BABEL_ENV=production BABEL_OUTPUT=cjs babel src --out-dir lib/js --ignore __tests__ --copy-files",
90-
"build:es": "cross-env BABEL_ENV=production BABEL_OUTPUT=esm babel src --out-dir lib/es --ignore __tests__ --copy-files",
73+
"build:js":
74+
"cross-env BABEL_ENV=production BABEL_OUTPUT=cjs babel src --out-dir lib/js --ignore __tests__ --copy-files",
75+
"build:es":
76+
"cross-env BABEL_ENV=production BABEL_OUTPUT=esm babel src --out-dir lib/es --ignore __tests__ --copy-files",
9177
"build:storybook": "build-storybook --output-dir docs",
9278
"clear": "rimraf ./lib",
9379
"commitmsg": "validate-commit-msg",
9480
"coverage": "yarn test -- --coverage",
9581
"create-github-release": "conventional-github-releaser -p angular",
9682
"format": "eslint --fix {src,docs/docs}/**/*.js",
97-
"lint": "eslint {src,docs/docs}/.",
83+
"lint": "eslint {src,docs/docs}/. && tsc --project types",
9884
"precommit": "yarn lint-staged && yarn test",
9985
"prepare": "yarn clear && yarn build",
10086
"prepublishOnly": "yarn test",

types/index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react';
2+
3+
export default class IntersectionObserver extends React.Component<Props> {}
4+
5+
interface Props {
6+
children: React.ReactElement<any>;
7+
root?: string | Element | null;
8+
rootMargin?: string;
9+
threshold?: number | number[];
10+
onlyOnce?: boolean;
11+
disabled?: boolean;
12+
onChange: (entry: IntersectionObserverEntry) => void;
13+
}

types/test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react';
2+
import Observer from '..';
3+
4+
const noop = () => {};
5+
const Component = () => <span />;
6+
7+
<Observer threshold={1} disabled={false} root="#foo" rootMargin="10px" onChange={noop}>
8+
<span style={{ height: 1, display: 'block' }} />
9+
</Observer>;
10+
11+
<Observer threshold={[0.5, 1]} onlyOnce root={document.body} onChange={noop}>
12+
<Component />
13+
</Observer>;

types/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react",
4+
"noEmit": true
5+
}
6+
}

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7198,6 +7198,10 @@ typedarray@^0.0.6:
71987198
version "0.0.6"
71997199
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
72007200

7201+
typescript@^2.6.2:
7202+
version "2.6.2"
7203+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
7204+
72017205
ua-parser-js@^0.7.9:
72027206
version "0.7.14"
72037207
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.14.tgz#110d53fa4c3f326c121292bbeac904d2e03387ca"

0 commit comments

Comments
 (0)