microsoft / microsoft/TypeScript

Common property check isn't performed when the target has any index signature

Aperta
#55,709 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: check: Excess Property Checking Possible Improvement
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

common property check weak type index signature

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play?noErrorTruncation=true&ts=5.3.0-dev.20230911#code/C4TwDgpgBAIhA2BDEAeAKnJIoQB7AgDsATAZylOACcBLQgcwD4oBeKDBZKAHykIFcAtgCMIVANwAoSXQJUAZogDG0ALLKAFnQgBhAPaF5Neukxc8BEuUq0GzAN6SoUUJFIB+AFxR+hANaEegDuhFLOiPJyXlCOzs4A2gDSUHSwnKgcWIwAutECImJhUAC+UsXSxBBKSFTQ8r5KwDQGLhCUKE7sZtgWRGQU1HT0ADSdaPqGxjj4feTqSlqEugZGJpnIjKOMABRKK8be9i7gbYdQlVik3uvYxSVQAGTsE6sAlN4Abno0xFKSBJRtrFjm5DndEORgc4LsgrlAAEQGaCkKoGYjwngIpFQQR0fgEeFFYqjcKRMSHTrOAD0VKgAAFgKQALR4SCNFlUKh6KiUqB6PRgUgAfWAWmFNGFvgCwUIQphIG8AEYAAzKkklUbFV5-eqERrNQitSgAJnQ00s-SO8Vw3gABj8mQASez5URUYq27LeGxDEo7RDXV4xcoA4DGoGdGn0xks3Bs4Acrk85xURAkPSCbzUfgQTXa6S6-UtUMAZjNvSsMSg1u9IBEengXoGtnofu2AfYQfsIbawBLEeptIZzNZVQTYiTnVT6czLioObzUiAA

💻 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il TypeScript Playground collegato e confronta i tre esempi in test, test2 e test3. Traccia il comportamento del controllo delle proprietà comuni con firme di indice mappate, di template literal e di simbolo; il lavoro è completato quando sono stabiliti i diagnostici previsti e il trattamento atteso di tutti e tre i casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.