microsoft / microsoft/TypeScript
Make `satisfies` configurable to allow excess properties in nested values
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verschachtelten Konfigurationsbeispiel und der im Issue beschriebenen aktuellen Diagnose von satisfies zu überschüssigen Eigenschaften. Kläre die vorgeschlagene Konfigurationsgrenze und überprüfe anschließend, dass verschachtelte zusätzliche Eigenschaften akzeptiert werden, während Fehler aufgrund ungültiger Konfiguration weiterhin gemeldet werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100