microsoft / microsoft/TypeScript
Common property check isn't performed when the target has any index signature
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 Search Terms
common property check weak type index signature
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type Delay<TDelay extends string> = TDelay | number;
interface MachineConfig<TDelay extends string> {
types?: unknown;
after?: {
[K in Delay<TDelay>]?: number;
};
}
declare function test<
TDelay extends string,
TConfig extends MachineConfig<TDelay>,
>(config: { types: { delays: TDelay } } & TConfig): void;
test({
types: {} as {
delays: "one second" | "one minute";
},
after: {
// @ts-expect-error
oops_this_is_unknown_delay: 100,
},
});
function test2<T extends { [x: `id-${number}`]: string }>(a: T) {}
test2({
// @ts-expect-error
random: true,
});
function test3<T extends { [x: symbol]: string }>(a: T) {}
test3({
// @ts-expect-error
random: true,
});
🙁 Actual behavior
No errors are raised here since index signatures turn off the common property check completely.
🙂 Expected behavior
I don't have a good intuition about the common property check so I'm not sure if all of those 3 examples should be treated as bugs/possible improvements. I think though that especially the first one is surprising because I have a list of 2 concrete string properties that are meant to be allowed there and yet the unrelated~ index signature for numbers turns off this check, leading to accidental problems at runtime.
Additional information about the issue
No response
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 TypeScript Playground enlazado y compara los tres ejemplos de test, test2 y test3. Traza cómo se comporta la comprobación de propiedades comunes con signaturas de índice mapeadas, de template literal y de símbolo; se considera terminado cuando estén establecidos los diagnósticos previstos y el tratamiento esperado de los tres casos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100