Microsoft/TypeScript

`satisfies` changes the generic type, "resolves" it immediately

Open

#52.394 geöffnet am 24. Jan. 2023

Auf GitHub ansehen
 (12 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: check: Type InferenceHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

Bug Report

It seems that using satisfies on a value that is bound to a generic type, in some way resolves the generic type at that place.

const foo = <T extends 1 | 2>(bar: T) => {
  // PROBLEM: a and b should have the same type.
  const a = bar satisfies any; // using any type that doesn't use the generic T here creates this problem
  //    ^? 1 | 2
  const b = bar;
  //    ^? T extends 1 | 2
}

Playground link

🔎 Search Terms

satisfies changes type, generic, widening

🕗 Version & Regression Information

Using 4.9.4 now with satisfies and noticed this.

  • This changed between versions 4.9 and 4.8 when satisfies was introduced
  • This is the behavior in every version I tried, and I reviewed the FAQ
  • I was unable to test this on prior versions because satisfies didn't exist

⏯ Playground Link

Playground link

🙁 Actual behavior

a and b have different types as seen in the playground

🙂 Expected behavior

satisfies should be a no-op

Contributor Guide