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

setter in declaration file gets any as return type iso void #1215

Closed
1 task done
PissedCapslock opened this issue Feb 21, 2020 · 3 comments · Fixed by redpeacock78/cie.js#6
Closed
1 task done

setter in declaration file gets any as return type iso void #1215

PissedCapslock opened this issue Feb 21, 2020 · 3 comments · Fixed by redpeacock78/cie.js#6
Labels
bug Functionality does not match expectation

Comments

@PissedCapslock
Copy link
Contributor

Expected Behavior

When running Typedoc on the following declaration file, I expect that the setter has void as return type.

/**
 * The Foo class
 */
declare class Foo {
    private _bar;
    /**
     * The bar method
     * @return something
     */
    get bar(): string;
    /**
     * The setter for the bar method
     * @param bar
     */
    set bar(bar: string);
}
export { Foo };

Actual Behavior

The generated documentation says that the setter has any as return type.

This is also visible in the json:

"setSignature": [                                        
	{                                                    
		"id": 5,                                         
		"name": "__set",                                 
		"kind": 1048576,                                 
		"kindString": "Set signature",                   
		"flags": {                                       
			"isExported": true                           
		},                                               
		"comment": {                                     
			"shortText": "The setter for the bar method",
			"returns": "something\n"                     
		},                                               
		"parameters": [                                  
			{                                            
				"id": 6,                                 
				"name": "bar",                           
				"kind": 32768,                           
				"kindString": "Parameter",               
				"flags": {                               
					"isExported": true                   
				},                                       
				"comment": {                             
					"shortText": "\n"                    
				},                                       
				"type": {                                
					"type": "intrinsic",                 
					"name": "string"                     
				}                                        
			}                                            
		],                                               
		"type": {                                        
			"type": "intrinsic",                         
			"name": "any"                                
		}                                                
	}                                                    
],

Steps to reproduce the bug

Run Typedoc on the declaration file mentioned above using

typedoc --mode modules --out docs --includeDeclarations --excludeExternals Foo.d.ts

The setter will have any as return type.

Note that it works as expected when using a .ts file instead of the corresponding .d.ts file. Looking at the Typedoc code base, there are tests that cover the .ts scenario but none for the .d.ts case.

Not sure if this is a Typedoc issue or rather a problem with Typescript itself. My attempt at debugging this problem gave me the idea that the Typescript compiler returns a different return type for both cases.

Environment

  • Typedoc version: typedoc@0.16.10
  • Node.js version: v12.11.1
  • OS: Ubuntu
@PissedCapslock PissedCapslock added the bug Functionality does not match expectation label Feb 21, 2020
PissedCapslock added a commit to PissedCapslock/typedoc-default-themes that referenced this issue Feb 21, 2020
@PissedCapslock
Copy link
Contributor Author

You can work around this issue in the theme by hardcoding that setters have void as return type. Did this in PissedCapslock/typedoc-default-themes@fa439d8

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Feb 22, 2020

This is really weird. I would have expected the return type in both cases to be string since you can do this:

const foo = new Foo();
const bar: string = foo.bar = 'str';

Should getters/setters even have return types? Hovering over the property in the playground shows (property) Foo.bar: string

@PissedCapslock
Copy link
Contributor Author

No, Typescript gives an error when you try to define a return type for a setter.
That's why I felt confident in adjusting my custom theme to simply hardcode void as return type for setters.

@Gerrit0 Gerrit0 added this to To do in Version 0.21 via automation Jun 15, 2021
@Gerrit0 Gerrit0 moved this from To do to Done in Version 0.21 Jun 15, 2021
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
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants