Getting one of optional types
Hi everyone, how can I get one of the types of | type? I can't create subtypes as the type is generated (Sub1 | Sub2 is impossible). https://www.typescriptlang.org/play?#code/C4TwDgpgBAogHgQwLZgDbQLxQN4CgoFQD6RokAdshAFxQBEAigK4QBOId+hSECAzk1YQ+tPIXHFS4CJR606ERCnQBGThMIALCNtp9grAJbkA5lwIBfXBagAfHOclkZVeczYdHPfoOGjH4iTOsjT0ishoEABM6hpQwMLAegbGZuJWVrgA9FlQmgD2AO5QAMYI5FCGUCYQwFD55ND5AGbxBXzQznwA-LjOUABKwkyowCpQWGKEQdIhbizssQQ8fAJCIg5xTrOuYUqRagFaOqH6RqaOGbjZuf1DAqMTUADK+TwA4jJshiUAYkzkEoAHngEXQABo6N41sI6OC9mCIGoAHw3eqsKB8N61TSpKCoQwAa06uL4QA
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
3 Replies
i dont fully understand your example tbh
but your type is already a discriminated union
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
so ts infers which of the possible types something will be