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

How Do you import this from typescript and use it? #171

Open
radiantone opened this issue Jun 1, 2024 · 4 comments
Open

How Do you import this from typescript and use it? #171

radiantone opened this issue Jun 1, 2024 · 4 comments

Comments

@radiantone
Copy link

I tried many variations but nothing works

@kristianmandrup
Copy link

Try adding a comment-parser.d.ts file in. a @types folder in your root or src folder

Ensure that TypeScript is aware of this file by including its path in your tsconfig.json:

{
  "include": ["src/**/*", "@types/**/*"]
}

comment-parser.d.ts

declare module 'comment-parser' {
  import { ParsedComment } from 'comment-parser/lib/types'; // Adjust import path if necessary

  export function parse(source: string): ParsedComment[];
}

or

declare module 'comment-parser' {
  interface Tag {
    tag: string;
    name: string;
    type?: string;
    optional?: boolean;
    default?: string;
    description: string;
    problems: any[];
    source: string[];
  }

  interface ParsedComment {
    description: string;
    tags: Tag[];
  }

  export function parse(source: string): ParsedComment[];
}

@brettz9
Copy link
Contributor

brettz9 commented Aug 25, 2024

Should be no need for a declaration file.

import {parse as commentParser} from 'comment-parser';

// See the structure yourself
console.log(
  commentParser(`
    /**
     * @param {someType} someName A description
     */
`)
);

@kristianmandrup
Copy link

I got it working with the above solution, but sometimes it is just a local TS server issue. I've seen that frequently with VS Code. Sometimes it can be solved via Cmd-P Restart TS Server, sometime with a full reboot of the IDE.

@rhys-vdw
Copy link

rhys-vdw commented Nov 16, 2024

Just added latest, it does not appear to export any type info:

Could not find a declaration file for module 'comment-parser'. 'c:/Users/rhysv/Projects/lua-doc-extractor/node_modules/comment-parser/lib/index.cjs' implicitly has an 'any' type.\n Try npm i --save-dev @types/comment-parser if it exists or add a new declaration (.d.ts) file containing declare module 'comment-parser';

Restarting TS server did not work, but also I haven't had such a problem with any other package.

It's strange because I can see the type definitions in the module folder, but VSCode doesn't seem to want to use them.

UPDATE:
I ended up writing my own type definition using the example in the readme. Would love to use the exported types, but they simple don't resolve.

You can see yourself here: https://github.com/rhys-vdw/lua-doc-extractor/tree/d6676877e5e1d9802ddb832941b998b14cf02400

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

4 participants