Skip to content

JSDoc: Support @readonly tag #17233

Closed

Description

TypeScript Version: nightly (2.5.0-dev.20170712)

Code

class C {
	constructor() {
		/**
		 * @readonly
		 * @type {number}
		 */
		this.x = 0;
	}

	m() {
		this.x = "1"; // Error
		this.x = 1; // No error
	}
}

Expected behavior:

Both lines in m are errors.

Actual behavior:

No error when trying to write to @readonly property.

Activity

  1. added
    Domain: JSDoc
    Suggestion
    on Aug 31, 2017
  2. niedzielski commented on Oct 14, 2018

    @niedzielski

    This would be awesome! There's already support for Readonly and readonly in JSDoc closure syntax. E.g.:

    /** 
     * @typedef {Readonly<{
     *   foo: ReadonlyArray<Foo>
     *   bar: number
     * }>} Baz
     */
    /**
     * @typedef {{
     *   readonly foo: ReadonlyArray<Foo>
     *   readonly bar: number
     * }} Baz
     */

    Both of the above examples work as expected. However, resolving this ticket would enable readonly support for member properties too:

    /**
     * @typedef {Object} Baz
     * @prop {ReadonlyArray<Foo>} foo This syntax supports comments.
     * @prop {number} bar But there's no support for marking properties as @readonly.
     */
  3. added
    Domain: JavaScript
    and removed on Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: JSDocDomain: JavaScriptIn DiscussionSuggestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions