node-typescript-parser icon indicating copy to clipboard operation
node-typescript-parser copied to clipboard

Add more information on return type of methods

Open jpike88 opened this issue 7 years ago • 6 comments

FunctionDeclaration {
  name: 'getNotificationSettingsForUser',
  isExported: false,
  type: 'Promise<{\n    notificationRows: any;\n}>',
  start: 5886,
  end: 6006,
  parameters:
   [ ParameterDeclaration { name: 'this', type: 'ApiHandler', start: 5934, end: 5950 },
     ParameterDeclaration { name: 'userID', type: 'any', start: 5952, end: 5963 } ],
  variables: [] }

The type variable is all string, how can we improve analysis to get at its structure?

jpike88 avatar Sep 25 '18 08:09 jpike88

I was just about to create an issue for this as well. It'd be great to have the return types parsed like everything else is, rather than just a string.

fennecbutt avatar Oct 11 '18 16:10 fennecbutt

Try my fork out, let me know if you improve it further and submit PRs to it. I have it on npm as typescript-parser-deluxe. This repo is too sluggish to rely on

jpike88 avatar Oct 12 '18 01:10 jpike88

Did you mean that your fork provides the return type structure? Or that I should get it in there & PR?

I tried typescript-parser-deluxe and the return type is still provided as: "type": "{\n a: number;\n b: number;\n }",

I'll see what I can do about getting it to provide it in a structured way. I have a feeling that the reason that it provides the return type as a string like that is because the referenced types are unknown. I'm going to try parsing the node/es6 declarations as well as my own and see if that helps the parser fill in the blanks...

Edit: after testing with a simplified return type (an object with static proprties set to constant values) it still provides the return type as a string. I'll look into the changes required to get the return type provided as a structure rather than a string.

Cheers for your help @jpike88

fennecbutt avatar Oct 16 '18 10:10 fennecbutt

Both! I will ensure the library is kept up to date. You'll notice a typeArguments property on some nodes, that's me exposing types via an alternate means. I didn't want to introduce breaking changes to the library

jpike88 avatar Oct 17 '18 06:10 jpike88

@jpike88 Would the pull request #101 be something that would be desirable in your typescript-parser-deluxe ? The most important commit was the first one which is called: 'Added better js types'

What it does basically is add better type detection more so for JS then TS. If so I will work on merging it into it.

mundusnine avatar Oct 24 '18 16:10 mundusnine

Yep go for it

jpike88 avatar Oct 25 '18 01:10 jpike88