adobe-client-data-layer
adobe-client-data-layer copied to clipboard
Provide type definition for TypeScript
Not a bug, but a feature request: Many front end developers nowadays write their scripting code in TypeScript instead of JavaScript. It would be great if this project would provide type definitions for the data-layer object.
Even better would be, if it would be possible to just import it in any .ts file and use it directly as an object without relying on the window object. Because like this we can make sure the object is there as it will be in the same transpiled js file and we don't need the [] fallback.
I created an interface in my project which I can share, but I am sure the EventListener is not the correct type in your case, but maybe it helps to give some ideas (I currently don't use the EventListener methods, so I didn't spend too much time on it):
interface AdobeEventOptions {
path?: string;
scope?: string;
}
interface AdobeDataLayer {
push(fn: (dl: AdobeDataLayer) => void): number;
push<T extends object>(...args: T extends Function ? Array<never> : Array<T>): number;
getState(reference?: string): any;
addEventListener(type: string, listener: EventListener, options?: AdobeEventOptions): never;
removeEventListener(type: string, listener?: EventListener): never;
}
I know any
is not very TypeScript. In my case I use the interface I created for my datalayer object as a return type, but to be generic enough this might be the only way.
That's great, thanks @onyx-blackbird, I agree that such type definition would be helpful for TypeScript projects!