sinoon / type-challenges

Collection of TypeScript type challenges with online judge
https://tsch.js.org/
0 stars 0 forks source link

Awaited #1

Open sinoon opened 4 years ago

sinoon commented 4 years ago

Please follow the template and fill the info. A PR will be auto-generated and always reflect on your changes.

Detailed solution/guide is not required, but please be sure the challenge is solvable.

Info

Basic info of your challenge questions,

difficulty: easy # medium / hard / extreme
title: Awaited
tags: promise # separate by comma
editor:
  github: sinoon
  name: sinoon
author: 
  github: maciejsikora
  name: Maciej Sikora

Question

If we have a type which is wrapped type like Promise. How we can get a type which is inside the wrapped type? For example if we have Promise how to get ExampleType?

This question is ported from the original article by @maciejsikora

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.

type Awaited = any

Test Cases

Provide some test cases for your challenge, you can use some utils from @type-challenges/utils for asserting.

import { Equal, Expect } from '@type-challenges/utils'

type X = Promise<string>
type Y = Promise<{ field: number }>

type cases = [
  Expect<Equal<Awaited<X>, string>>
  Expect<Equal<Awaited<Y>, { field: number }>>
]
github-actions[bot] commented 4 years ago

2 - Pull Request updated.

2020-09-11T15:54:52.720Z Preview in Playground