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

Function property is mis-interpreted as method #1637

Closed
hez2010 opened this issue Jul 26, 2021 · 4 comments
Closed

Function property is mis-interpreted as method #1637

hez2010 opened this issue Jul 26, 2021 · 4 comments
Labels
bug Functionality does not match expectation

Comments

@hez2010
Copy link

hez2010 commented Jul 26, 2021

Search terms

Function property, method

Expected Behavior

interface Foo {
    prop: () => void
}

This should be interpreted as a function property:

"name": "prop",
"kind": 1024,
"kindString": "Property",
"flags": {},
...

Actual Behavior

Instead, typedoc generates a method node for it:

"name": "prop",
"kind": 2048,
"kindString": "Method",
"flags": {},
...

Steps to reproduce the bug

test.ts:

interface Foo {
    prop: () => void
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "es2020"
    }
}
typedoc test.ts --json result.json

Environment

  • Typedoc version: 0.21.4
  • TypeScript version: 4.4
  • Node.js version: v14.17.0
  • OS: Windows 11
@Simek
Copy link

Simek commented Jul 28, 2021

Refs #1624 (98331b5)

In current project I'm using TypeDoc raw data output. It looks like after the change mentioned above the React/React Native functional components props data has been stripped or moved too.

If I downgrade to 0.21.2 the output is correct again, but there are still comment data missing or misplaced in few cases. The only solution for me right now was a revert to latest version from 0.20 branch.

Environment

  • Typedoc version: 0.21.4
  • TypeScript version: 4.0.3
  • Node.js version: v15.11.0
  • OS: macOS 11.5

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 31, 2021

This should be interpreted as a function property:

From a code generation perspective that targets compiled languages, I can see your point here... however, I'm not sure that this behavior is something that should be reverted. TypeDoc has done the same thing for property-methods for a long time, its detection for these was just improved in a way that broke your use case.

class Foo {
  iAmMethod = (x: string) => parseInt(x)
}

React/React Native functional components props data has been stripped or moved too.

I can't seem to reproduce this, open a new issue with a reproduction to keep different problems separate please.

@Gerrit0 Gerrit0 added the wontfix Declining to implement label Aug 10, 2021
@Gerrit0 Gerrit0 closed this as completed Aug 10, 2021
@tsvetomir
Copy link
Contributor

Just got bitten by this issue after an upgrade. Seems wrong for my particular use case too.

Now the same member will show as a method in the interface and as a property in the implementing class:

interface Foo {
    prop: () => void;

// "kindString": "Method"
}

class FooClass implements Foo {
    prop: () => void;

//  "kindString": "Property",
//  "implementationOf": {
//      "type": "reference",
//      "name": "Foo.prop"
//  }
}

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 12, 2022

Hmm... that's actually a really good argument for not turning property-methods into methods in type space...

Once TS 4.7 releases, with explicit variance annotations, it won't be necessary to declare intended methods as properties in order to get the correct variance, which should make property-methods less frequent... if the comment plugin is updated so that it can properly inherit comments from property-methods, I think I'm okay with reverting this...

@Gerrit0 Gerrit0 added revisit and removed wontfix Declining to implement labels Apr 13, 2022
@Gerrit0 Gerrit0 reopened this May 25, 2022
@Gerrit0 Gerrit0 closed this as completed in 3622a81 Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests

4 participants