Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide type definition for TypeScript #99

Open
onyx-blackbird opened this issue Sep 1, 2020 · 2 comments
Open

Provide type definition for TypeScript #99

onyx-blackbird opened this issue Sep 1, 2020 · 2 comments
Labels
enhancement New feature, or improvement to an existing feature. good first issue Good starter issue for new contributors.

Comments

@onyx-blackbird
Copy link

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.

@jckautzmann jckautzmann added the enhancement New feature, or improvement to an existing feature. label Sep 1, 2020
@onyx-blackbird
Copy link
Author

onyx-blackbird commented Sep 2, 2020

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.

@gabrielwalt
Copy link
Member

That's great, thanks @onyx-blackbird, I agree that such type definition would be helpful for TypeScript projects!

@gabrielwalt gabrielwalt added the good first issue Good starter issue for new contributors. label Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, or improvement to an existing feature. good first issue Good starter issue for new contributors.
Projects
None yet
Development

No branches or pull requests

3 participants