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

Support: How to import it in typescript? #48

Closed
distante opened this issue Jan 24, 2021 · 4 comments
Closed

Support: How to import it in typescript? #48

distante opened this issue Jan 24, 2021 · 4 comments
Assignees

Comments

@distante
Copy link

distante commented Jan 24, 2021

Sorry I pressed ENTER without notice!

I saw it has typescript definitions but I can not find the way to imported so the types are recognized. What I am doing for now is declaring the module my sefl with:

declare interface CssSelectorGeneratorParams {
  selectors?: string[];
  root?: Element;
  blacklist?: string[];
  whitelist?: string[];
  combineWithinSelector?: true;
  combineBetweenSelectors?: true;
  includeTag?: true;

}
declare module 'css-selector-generator' {
  export default function getCssSelector(targetElement: Element, options: CssSelectorGeneratorParams): string;
}

But of course it could break at any time and it does not have and documentation included.

fczbkk added a commit that referenced this issue Jan 24, 2021
@fczbkk
Copy link
Owner

fczbkk commented Jan 24, 2021

@distante I have tried to add explicit path to the type definitions to the "package.json". According to the documentation, it should help:
https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html#editing-the-packagejson

Please try to upgrade to v2.1.3 (https://github.com/fczbkk/css-selector-generator/releases/tag/v2.1.3) and let me know, if it works for you.

@fczbkk fczbkk self-assigned this Jan 24, 2021
@distante
Copy link
Author

Yes, now it works @fczbkk, thank you!

@xblanc33
Copy link

Hi,

I have an issue with TypeScript type check but only with the selectors option

 suffix.push(getCssSelector(event.target, {
    selectors: ["id"]
})

TypeScript considers "id" as a string and not as a CssSelectorType.

Now if I try

selectors: [CssSelectorType.id], 

It tells me that this type is not exported in the module (index.d.ts), which is true.

Can you help me ?

fczbkk added a commit that referenced this issue Jan 15, 2022
@fczbkk
Copy link
Owner

fczbkk commented Jan 15, 2022

Hey @xblanc33, thanks for the report. You're right, the type of "selectors" property in options was set to an enum, which was not exported publicly. I have updated it so that it allows one of these strings:
"id" | "class" | "tag" | "attribute" | "nthchild" | "nthoftype"

Update to v3.5.3 and it should be typed correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants