What this snippet does
You can only access properties that exist on all members of a union, requiring type narrowing for specific methods.
Expected output
Compile Error: Property 'toUpperCase' does not exist on type 'string | number'.
Why practise typing this
Typing union and intersection types code builds muscle memory for the symbols and indentation TypeScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.
More TypeScript practice
- Defining a variable that can be string or numberUnion and Intersection Types · beginner
- Formatting a value that can be a string or numberUnion and Intersection Types · beginner
- Combining two object types with an intersectionUnion and Intersection Types · beginner
- Mixing mixins to create a LoggedUserUnion and Intersection Types · beginner
- Creating an impossible type intersectionUnion and Intersection Types · beginner
- Defining exact string literalsUnion and Intersection Types · beginner