Skip to content

Commit

Permalink
feat: Add basic TypeScript types (#26)
Browse files Browse the repository at this point in the history
* feat: Add basic TypeScript types

I do not expect these to be completely accurate.
However, they should be a decent starting point for further discussion!

* feat: Add LEVEL to the types for convenience

* fix: useRollbarConfiguration's return to void

* feat(ts): Improvements on typing and formatting

* feat(ts): Add types to package.json
  • Loading branch information
quinnturner authored Jan 25, 2022
1 parent 9e940f6 commit ad8f667
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
61 changes: 61 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Component, ReactNode } from "react";
import Rollbar, { Callback } from "rollbar";

export const LEVEL_DEBUG = "debug";
export const LEVEL_INFO = "info";
export const LEVEL_WARN = "warn";
export const LEVEL_ERROR = "error";
export const LEVEL_CRITICAL = "critical";
export type LEVEL =
| typeof LEVEL_DEBUG
| typeof LEVEL_INFO
| typeof LEVEL_WARN
| typeof LEVEL_ERROR
| typeof LEVEL_CRITICAL;

export interface ErrorBoundaryProps {
children: ReactNode;
fallbackUI?: ReactNode;
errorMessage?: string | (() => string);
extra?:
| Record<string | number, unknown>
| (() => Record<string | number, unknown>);
level?: LEVEL | (() => LEVEL);
callback?: Callback<any>;
}

interface ErrorBoundaryState {
hasError: boolean;
error: Error | null;
}

export class ErrorBoundary extends Component<
ErrorBoundaryProps,
ErrorBoundaryState
> {
resetError: () => void;
}
export class RollbarContext extends Component<{
children: ReactNode;
context?: string;
}> {}
export function useRollbar(): Rollbar;
export function useRollbarConfiguration(config: Rollbar.Configuration): void;
export function useRollbarContext(ctx?: string, isLayout?: boolean): void;
export function useRollbarPerson(person: object): void;
export function useRollbarCaptureEvent(metadata: object, level?: LEVEL): void;
export function isValidLevel(level: LEVEL): boolean;

export function historyContext(
rollbar: Rollbar,
args: {
formatter: (location: string, action: string) => string;
filter: (location: string, action: string) => boolean;
}
): (
v4Location: {
action: string;
filter: (location: string, action: string) => boolean;
},
v4action: string
) => void;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"directories": {
"lib": "dist"
},
"types": "index.d.ts",
"files": [
"dist",
"lib",
Expand Down

0 comments on commit ad8f667

Please sign in to comment.