Skip to content

Optional properties #347

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

Closed
ikokostya opened this issue Feb 7, 2016 · 8 comments
Closed

Optional properties #347

ikokostya opened this issue Feb 7, 2016 · 8 comments

Comments

@ikokostya
Copy link
Contributor

documentation skips optional properties in typedef declaration:

/**
 * @typedef {Object} Foo
 * @property {Number} a
 * @property {Number} [b]
 */
$ documentation build test.js -f json
[
  {
    "description": "",
    "tags": [
      {
        "title": "typedef",
        "description": null,
        "lineNumber": 1,
        "type": {
          "type": "NameExpression",
          "name": "Object"
        },
        "name": "Foo"
      },
      {
        "title": "property",
        "description": null,
        "lineNumber": 2,
        "type": {
          "type": "NameExpression",
          "name": "Number"
        },
        "name": "a"
      }
    ],
    "loc": {
      "start": {
        "line": 1,
        "column": 0
      },
      "end": {
        "line": 5,
        "column": 3
      }
    },
    "context": {
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 6,
          "column": 0
        }
      },
      "file": "/home/kostya/proj/typedef-test/test.js"
    },
    "typedef": {
      "name": "Foo",
      "type": {
        "type": "NameExpression",
        "name": "Object"
      }
    },
    "properties": [
      {
        "title": "property",
        "description": null,
        "lineNumber": 2,
        "type": {
          "type": "NameExpression",
          "name": "Number"
        },
        "name": "a"
      }
    ],
    "name": "Foo",
    "kind": "typedef",
    "members": {
      "instance": [],
      "static": []
    },
    "path": [
      "Foo"
    ]
  }
]

How I can define optional properties?

@tmcw
Copy link
Member

tmcw commented Feb 15, 2016

Optional properties cannot be specified at this point; JSDoc doesn't support optional properties and as a result doctrine (the parser documentation.js uses) doesn't either. If you're interested in rallying support for this idea, the first place to start would be to get it into the doctrine parser.

@ikokostya
Copy link
Contributor Author

Optional properties cannot be specified at this point; JSDoc doesn't support optional properties

jsdoc3 marks property b from my example as optional

screenshot_2016-02-15_07-47-00

@ikokostya
Copy link
Contributor Author

ikokostya commented Sep 13, 2016

doctrine supports optional properties since 1.4.0 version. I think this issue can be closed.

@arv
Copy link
Contributor

arv commented Sep 13, 2016

We need to infer it too:

type T = {
  opt?: number,
  req: string,
};

(I looked at this a few days ago and I didn't see any support in Doctrine?)

@arv arv reopened this Sep 13, 2016
@ikokostya
Copy link
Contributor Author

(I looked at this a few days ago and I didn't see any support in Doctrine?)

This feature was implemented yesterday.

This is output for property b with latest doctrine (don't forget reinstall node_modules):

{
  "name": "b",
  "lineNumber": 3,
  "type": {
    "type": "OptionalType",
    "expression": {
      "type": "NameExpression",
      "name": "Number"
    }
  }
}

@arv
Copy link
Contributor

arv commented Sep 14, 2016

I see. The type is optional, not the field. I guess we could work with that.

On Wed, Sep 14, 2016, 06:09 ikokostya [email protected] wrote:

(I looked at this a few days ago and I didn't see any support in Doctrine?)

This feature was implemented yesterday.

This is output for property b with latest doctrine (don't forget
reinstall node_modules):

{
"name": "b",
"lineNumber": 3,
"type": {
"type": "OptionalType",
"expression": {
"type": "NameExpression",
"name": "Number"
}
}
}


You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub
#347 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACzFYCcKLEhzyI5LQyeP1ERVuAdySYUks5qp_IhgaJpZM4HU-79
.

@ikokostya
Copy link
Contributor Author

ikokostya commented Sep 16, 2016

The type is optional, not the field.

Hmm. Yes, this is weird, but consistent with optional parameters which have OptionalType too.

@ikokostya
Copy link
Contributor Author

ikokostya commented Oct 6, 2016

#547 was merged. @arv Can this issue be closed?

@arv arv closed this as completed Oct 6, 2016
rhendric pushed a commit to rhendric/documentation that referenced this issue Sep 15, 2022
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