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
You need to provide a detailed description of your new challenge, either in English or Chinese are acceptable.
Detailed solution/guide is not required, but be sure the challenge is solvable.
Please follow the template and fill the info. A PR will be auto-generated and always reflect on your changes.
Info
Basic info of your challenge questions,
difficulty: medium # medium / hard / extremetitle: Type Lookuptags: union, map
Question
Sometimes, you may want to lookup for a type in a union to by their attributes.
In this challenge, I would like to have get the couponing type by searching for the common type field in the union Cat | Dog. In other words, I will expect to get Dog for LookUp<Dog | Cat, 'dog'> and Cat for LookUp<Dog | Cat, 'cat'> in the following example.
interfaceCat{type: 'cat'breeds: 'Abyssinian'|'Shorthair'|'Curl'|'Bengal'}interfaceDog{type: 'dog'breeds: 'Hound'|'Brittany'|'Bulldog'|'Boxer'color: 'brown'|'white'|'black'}constMyDog=LookUp<Cat|Dog,'dog'>// expected to be `Dog`
Template
This is the template for challengers to start the coding. Basically, you just need to change the name of your generic/function and leave to implementation any.
typeLookUp<U,T>=any
Test Cases
Provide some test cases for your challenge, you can use some utils from @type-challenges/utils for asserting.
Info
Basic info of your challenge questions,
Question
Sometimes, you may want to lookup for a type in a union to by their attributes.
In this challenge, I would like to have get the couponing type by searching for the common
type
field in the unionCat | Dog
. In other words, I will expect to getDog
forLookUp<Dog | Cat, 'dog'>
andCat
forLookUp<Dog | Cat, 'cat'>
in the following example.Template
This is the template for challengers to start the coding. Basically, you just need to change the name of your generic/function and leave to implementation
any
.Test Cases
Provide some test cases for your challenge, you can use some utils from
@type-challenges/utils
for asserting.The text was updated successfully, but these errors were encountered: