We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
satisfies
satisfies operator jsdoc
My suggestion meets these guidelines:
TypeScript has the satisfies operator, but there's no way to use this operator in JavaScript files with JSDoc.
Take the following TypeScript code:
type Foo = { bar: string; baz: number; } const x = { bar: "sldkfj", baz: 3, } as const satisfies Foo;
This is currently not possible in JavaScript files
The example above gives the benefit of both type checking x for errors, as well as autocompleting property names when adding new properties.
x
I think the same syntax for casting can be used here. Especially with the example above since that is already being cast:
/** * @typedef Foo * @property {string} bar * @property {number} baz */ const x = /** @type {const satisfies Foo} */ ({ bar: "bar", baz: 3, });
For cases where you don't want to cast as const similar syntax can be used:
as const
const x = /** @type {satisfies Foo} */ ({ bar: "bar", baz: 3, });
The text was updated successfully, but these errors were encountered:
As a workaround, for now the same effect can still be achieved using a generic function:
/** * @template {Foo} T * @param {T} x */ const satisfiesFoo = x => x; const x = satisfiesFoo(/** @type {const} */ ({ bar: "bar", baz: 3, }));
Sorry, something went wrong.
Duplicate of #51086. Used search terms: satisfies jsdoc in:title
satisfies jsdoc in:title
This already works since 5.0: #51753
/** * @typedef Foo * @property {string} bar * @property {number} baz */ /** @satisfies {Foo} */ const x = /** @type {const} */ ({ bar: "bar", baz: 3, }) const y = /** @type {const} @satisfies {Foo} */ ({ bar: "bar", baz: 3, })
TS playground
Ah sorry about that! Not sure how I missed this.
No branches or pull requests
Suggestion
π Search Terms
satisfies operator jsdoc
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
TypeScript has the
satisfies
operator, but there's no way to use this operator in JavaScript files with JSDoc.π Motivating Example
Take the following TypeScript code:
This is currently not possible in JavaScript files
π» Use Cases
The example above gives the benefit of both type checking
x
for errors, as well as autocompleting property names when adding new properties.Proposal
I think the same syntax for casting can be used here. Especially with the example above since that is already being cast:
For cases where you don't want to cast
as const
similar syntax can be used:The text was updated successfully, but these errors were encountered: