microsoft / microsoft/TypeScript
Make `satisfies` configurable to allow excess properties in nested values
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Suggestion
🔍 Search Terms
satisfies + (known properties, unknown properties, excess)
✅ 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
When using satisfies, the value should be allowed to have extra properties.
📃 Motivating Example
Satisfy is defined this way when I Google it:
meet the expectations, needs, or desires of (someone).
Right now, the satisfies operator does more than that. It's more like satisfies and goes no further than. Example:
interface User {
name: string
}
const john = {
name: 'John',
email: 'john@gmail.com',
} satisfies User
In the above, the value of john clearly does satisfy the interface User, but the compiler complains:
Type '{ name: string; email: string; }' does not satisfy the expected type 'User'.
Object literal may only specify known properties, and 'email' does not exist in type 'User'.
The first line of this is straight-up untrue! And it'd be really useful to be able to say "I have an object which I know is assignable to User, but it also has some specific extra stuff which I still care about.
💻 Use Cases
This first arose writing a very large, nested, complex config for a CMS. Right now it's a huge as const expression, which we have to carefully align with a type Config - but the type only defines some of the properties a config can have at compile time. The value is later passed to a function which expects a valid Config so we see invalid configuration errors in the wrong place. We have tried to use satisfies but hit the excess properties error for those properties not defined on the Config type. It's nested so we can't do satisfies Config & Record<string, unknown> except for top-level properties.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the nested configuration example and the current satisfies excess-property diagnostic described in the issue. Clarify the proposed configuration boundary, then verify that nested extra properties are accepted while invalid configuration errors remain reported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100