Fix 'as const'-like behavior in JSDoc type cast by rbuckton · Pull Request #45464 · microsoft/TypeScript (original) (raw)
The parens are also useful for performance reasons, otherwise we'd have to check every leading JSDoc comment of every expression in a JS file.
What I'd like is a shorter cast syntax (even with the parens). Something like /** {type} */(expr)
(removing the @type
). I know we allow you to write /** @type type */(expr)
(dropping the {}
), but that still feels awkward.
I'd also like a way to emulate postfix-!
in JSDoc, because the only options currently are a cast (which could be difficult to write from an inferred type), or a generic identity function that removes null | undefined
. Not sure what a good jsdoc syntax might be for that though, since there really isn't precedent in Clojure or jsdoc.app.
Something like one of these:
/** @type {!} /(foo.bar).baz; // just the !
prefix
/* @notnull /(foo.bar).baz; // a keyword-like tag
/* @! /(foo.bar).baz; // or some type of shorthand
/* {!} */(foo.bar).baz;
I'll have to see if there's an open issue for this and, if not, create one.