joarwilk / flowgen

Generate flowtype definition files from TypeScript
Other
657 stars 87 forks source link

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined #156

Closed pladaria closed 2 years ago

pladaria commented 2 years ago

I'm getting this error by trying to convert an autogenerated d.ts file, I've reduced the problematic case to the minimum:

// index.d.ts
export declare const fn: () => Promise<void>;

Command:

npx flowgen index.dts

Output:

(node:227208) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
    at getFullyQualifiedName (/home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/printers/node.js:128:68)
    at /home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/printers/node.js:521:41
    at Object.fn (/home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/env.js:10:12)
    at Object.functionType (/home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/printers/function.js:20:45)
    at /home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/printers/node.js:373:33
    at Object.fn (/home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/env.js:10:12)
    at Object.propertyDeclaration (/home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/printers/declarations.js:46:31)
    at /home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/printers/node.js:551:36
    at fn (/home/pladaria/bra/webview-bridge/node_modules/flowgen/lib/env.js:10:12)
    at Array.map (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:227208) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:227208) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

If I downgrade flowgen to 1.11, it works:

npx flowgen@1.11 index.d.ts

Produces:

/**
 * Flowtype definitions for index
 * Generated by Flowgen from a Typescript Definition
 * Flowgen v1.11.0
 */

declare export var fn: () => Promise<void>;