Proxy property in setter has never type (with MRE)

Summarized

Writing produces type intersection in TS.

Detailed

This is a copy of the answer from the official repo microsoft/TypeScript#47295, this is a functionality that “work as intended”.

In most of your setups, the type of prop is not narrowed down from "num" | "str" | "arr"; since you’re writing to target[prop] rather than reading from it, that produces an intersection (not a union) of all the possible types it could refer to. If there’s no overlap, the intersection collapses to never, because there’s no possible value that works for all of them.

This answer is created to close the question.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top