microsoft / microsoft/TypeScript
Make `satisfies` configurable to allow excess properties in nested values
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’esempio di configurazione annidata e con l’attuale diagnostica sulle proprietà in eccesso di satisfies descritta nell’issue. Chiarisci il confine di configurazione proposto, quindi verifica che le proprietà aggiuntive annidate vengano accettate, mentre gli errori di configurazione non valida continuino a essere segnalati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100