-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Suggestion
π Search Terms
- property restriction
- koa middleware
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
// Error: Property 'foo' is not set once.
async function koaMiddleware1(
ctx: {pending foo: 1}
) {}
// OK
async function koaMiddleware2(
ctx: {pending foo: 1}
) {
ctx.foo = 1
}
// OK
async function koaMiddleware3(
ctx: {pending foo: 1}
) {
ctx.foo = ctx.foo ?? 1
}Calling function
- Maybe like below?
// OK
await koaMiddleware2({})
// OK
await koaMiddleware2({foo: 1})
- Or maybe cast
koaMiddlewareImplementXto another functionkoaMiddlewareXwith type withctx: {foo: 1}
π Motivating Example
Describe restriction on a koa middleware, should always set specific properties.
π» Use Cases
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript