You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The declaration of withoutAsConst fails, as type: "text" fails to be inferred as "text", and instead infers as string in this situation:
Type 'string' is not assignable to type '"text" | "image" | "video" | "document" | undefined'.
π Expected behavior
The declaration of withoutAsConst should succeed. Typescript understands that the only valid values in this position are "text" | "image" | "video" | "document" | undefined from the contextual type, so the literal "text" should match that.
Bug Report
π Search Terms
infer contextual string union
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The declaration of
withoutAsConstfails, astype: "text"fails to be inferred as"text", and instead infers asstringin this situation:π Expected behavior
The declaration of
withoutAsConstshould succeed. Typescript understands that the only valid values in this position are"text" | "image" | "video" | "document" | undefinedfrom the contextual type, so the literal"text"should match that.