Skip to content

property restriction: pending propertyΒ #48331

@loynoir

Description

@loynoir

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

  1. Maybe like below?
// OK
await koaMiddleware2({})

// OK
await koaMiddleware2({foo: 1})
  1. Or maybe cast koaMiddlewareImplementX to another function koaMiddlewareX with type with ctx: {foo: 1}

πŸ“ƒ Motivating Example

Describe restriction on a koa middleware, should always set specific properties.

πŸ’» Use Cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions