microsoft / microsoft/TypeScript
Make `satisfies` configurable to allow excess properties in nested values
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el ejemplo de configuración anidada y el diagnóstico actual de propiedades excedentes de satisfies descrito en el issue. Aclara el límite de configuración propuesto y, a continuación, verifica que las propiedades adicionales anidadas se acepten, mientras que los errores de configuración no válida sigan notificándose.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100