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

Param Default Values #737

Closed
LittleBitQuacky opened this issue Apr 17, 2017 · 5 comments
Closed

Param Default Values #737

LittleBitQuacky opened this issue Apr 17, 2017 · 5 comments

Comments

@LittleBitQuacky
Copy link

Hi,

I have methods that have parameters with default values that don't get displayed correctly. Maybe I am doing something wrong.

 * @namespace Test
 * @desc A test
 */

class Test {

	/**
	 * @static
	 *
	 * @param {String} [str=""]
	 * @param {Boolean} [ret=false]
	 */

	static a(str = "", ret = false){

	}

	/**
	 * @static
	 *
	 * @param {String} [back=true] // Incorrect type here ignore this
	 */

	static b(back = true){

	}

	/**
	 * @static
	 */

	static c(){

	}

}

▾ a(str = "", ret = false)
    a(str: String?, ret: Boolean?)
    
    Parameters
          str (String? = "")
          ret (Boolean? = false)

Here is a screen shot of how it looks: http://i.imgur.com/nIkcz6b.png

@tmcw
Copy link
Member

tmcw commented Apr 17, 2017

Hi,

Could you describe what the intended result is? Is the ? the issue here?

@LittleBitQuacky
Copy link
Author

LittleBitQuacky commented Apr 17, 2017

Hi,

I was expecting something more like the example on your website (http://documentation.js.org/html-example/#popup/sethtml), but maybe that is a different / older theme?

I suppose this mostly comes down to the theme. I modified the example HTML on your site to show how I would like it to be.

http://i.imgur.com/J8ueB3B.png

But yeah, the question marks would be the focus for this issue. Kinda makes it confusing, wasn't sure if it was something I was doing wrong, or intended behavior, as I've never used a tool to do documentation before.

Thanks

@arv
Copy link
Contributor

arv commented Apr 17, 2017

We are using Flow's type syntax and the question mark is for types that can be null or undefined.

There is certainly room for improvements here. Having the question mark when we have the equals is not really right.

@tmcw
Copy link
Member

tmcw commented Apr 25, 2017

Got it. Okay, yeah, so...

@param {number} [foo=5] bar

Produces

        {
            "title": "param",
            "description": "bar",
            "type": {
                "type": "OptionalType",
                "expression": {
                    "type": "NameExpression",
                    "name": "number"
                }
            },
            "name": "foo",
            "default": "5"
        }

But that isn't really what we want - what we want, both out of the doctrine tag and out of inference, is more like

        {
            "title": "param",
            "description": "bar",
            "type": {
                  "type": "NameExpression",
                  "name": "number"
            },
            "name": "foo",
            "default": "5"
        }

Right? I can start by implementing this on the inference side, and we could massage Doctrine output to produce this, and then it'd be an upstream change to doctrine.

@arv
Copy link
Contributor

arv commented Apr 25, 2017

I'm torn about this. From a type annotation POV the type is just number but from a documentation POV the type is number | undefined since the casket can use either.

@tmcw tmcw closed this as completed in #757 Apr 26, 2017
tmcw added a commit that referenced this issue Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants