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

JSDoc: Support @readonly tag #17233

Closed
ghost opened this issue Jul 16, 2017 · 1 comment · Fixed by #35790
Closed

JSDoc: Support @readonly tag #17233

ghost opened this issue Jul 16, 2017 · 1 comment · Fixed by #35790
Labels
Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ghost
Copy link

ghost commented Jul 16, 2017

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.

@ghost ghost added the Salsa label Jul 16, 2017
@mhegazy mhegazy added Domain: JSDoc Relates to JSDoc parsing and type generation Suggestion An idea for TypeScript labels Aug 31, 2017
@niedzielski
Copy link

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.
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants