diff --git a/types/react-tracking/index.d.ts b/types/react-tracking/index.d.ts index 305cb03895..9b03b98275 100644 --- a/types/react-tracking/index.d.ts +++ b/types/react-tracking/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-tracking 5.0 +// Type definitions for react-tracking 6.0 // Project: https://github.com/NYTimes/react-tracking // Definitions by: Eloy Durán // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -58,6 +58,12 @@ type ClassDecorator = (target: TFunction) => TFuncti type MethodDecorator = (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; export type Decorator = ClassDecorator & MethodDecorator; +export type TrackingContext = React.Context<{ + tracking: Options & { data?: {} } +}>; + +export const ReactTrackingContext: TrackingContext; + /** * This is the type of the `track` function. It’s declared as an interface so that consumers can extend the typing and * specify defaults, such as a global analytics schema for the tracking-info. diff --git a/types/react-tracking/test/react-tracking-with-types-tests.tsx b/types/react-tracking/test/react-tracking-with-types-tests.tsx index ec4c2d9ed7..252c71e500 100644 --- a/types/react-tracking/test/react-tracking-with-types-tests.tsx +++ b/types/react-tracking/test/react-tracking-with-types-tests.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Track, track as _track, TrackingProp, Options, Decorator } from 'react-tracking'; +import { Track, track as _track, TrackingProp, Options, Decorator, TrackingContext, ReactTrackingContext } from 'react-tracking'; function customEventReporter(data: { page?: string }) {} @@ -70,3 +70,18 @@ class Test extends React.Component { ); } } + +const TestContext = () => { + const trackingContext = { + tracking: { + data: { foo: 'bar' }, + dispatch: (data: {}) => data, + process: (x: string) => x + } + }; + return ( + +
hello how are you
+
+ ); +};