Skip to content

Commit

Permalink
Add type definitions for ResizeObserver API
Browse files Browse the repository at this point in the history
  • Loading branch information
chivesrs committed Mar 4, 2019
1 parent bc86129 commit fcfcae4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
19 changes: 19 additions & 0 deletions types/resize-observer-browser/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Type definitions for non-npm package resize-observer-browser 0.1
// Project: https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver, https://developers.google.com/web/updates/2016/10/resizeobserver, https://wicg.github.io/ResizeObserver/
// Definitions by: Chives <https://github.com/chivesrs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7

export class ResizeObserver {
constructor(callback: ResizeObserverCallback);
disconnect(): void;
observe(target: Element): void;
unobserve(target: Element): void;
}

export type ResizeObserverCallback = (entries: ResizeObserverEntry[]) => void;

export interface ResizeObserverEntry {
readonly target: Element;
readonly contentRect: DOMRectReadOnly;
}
13 changes: 13 additions & 0 deletions types/resize-observer-browser/resize-observer-browser-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ResizeObserver } from "resize-observer-browser";

function resizeObserverCreates(): void {
const resizeObserver: ResizeObserver = new ResizeObserver((entries) => {
const div = document.getElementById('display-div')!;
const rect = entries[0].contentRect;
div.textContent = `${rect.left} ${rect.right}`;
});
const div = document.getElementById('resized-div')!;
resizeObserver.observe(div);
resizeObserver.unobserve(div);
resizeObserver.disconnect();
}
24 changes: 24 additions & 0 deletions types/resize-observer-browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"dom",
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"resize-observer-browser-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/resize-observer-browser/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit fcfcae4

Please sign in to comment.