How Do you import this from typescript and use it?
I tried many variations but nothing works
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[];
}
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
*/
`)
);
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.
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-parserif it exists or add a new declaration (.d.ts) file containingdeclare 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