TypeScript: Exhaustive Pattern Matching on Classes with instanceof
hamy.xyz·4d
📘TypeScript
Preview
Report Post

DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)

TS has pretty good types and can do exhaustive pattern matching. Here’s an example of doing so with classes and instanceof - smth I didn’t think was possible (and neither did my AI).

See the full code and run it - [TS Playground](https://www.typescriptlang.org/play/?ssl=63&ssc=2&pln=32&pc=1#code/MYGwhgzhAEAiD2BzaBvAUNaEAOBTMA1gBQCUqGm0w8AdhPCLgHQhJEBEARmAE4HskA3BQC+aMWlCQYAYTAAXcphz5iZdJSq16jFm3YBZXAHd4A4ZjESpUaAGUahXEqx5CpF5mp0GzVog4ACQBLKHNRcTQ0ADMAVxpgeWDaaABbBWAAC2CaAJzsWPkALjgkaAAfaDlFSocnEhKAN3hggBMXYOiifMLoHIh5MATceGjSxHUKTB75JhV3EinoHlx5WJ4aC2gRaFwQCGdO7poCxX7B4dGqhUnNGbm3NSWVtY2tiS9tRVwAD0ywWIDYKNXAlGi4EE8aAAXj6J0KW28Oj8bAABnZMvBYiB2jR4IpEKtoJl…

Similar Posts

Loading similar posts...