DEV Community

Cover image for type variables in typescript
cem kaan kosali
cem kaan kosali

Posted on • Updated on

type variables in typescript

  1. I watched 20 minutes of Data structures. I finished Priority Queue.
  2. I've tried some different layouts in nativescript-vue in play.nativescript.org.
  3. I wrote a little bit more on functional typescript.

May be I will use StackLayout instead of GridLayout

        <StackLayout orientation="horizontal" backgroundColor="lightgray">
            <Label v-for="n in item.totalLabelsCount" :text="item.id"
                width="30" height="150" backgroundColor="white"
                class="border" />
        </StackLayout>
Enter fullscreen mode Exit fullscreen mode

I am trying to come with an idea about how to explain type variables in Typescript

Did you know there are type variables in typescript? You don't need to know type of a result from a function. You can just use a variable for whatever this type will be. Cool right?

function identity<T>(arg: T): T {
    return arg;
}
Enter fullscreen mode Exit fullscreen mode

Please check out:
https://www.typescriptlang.org/docs/handbook/functions.html#rest-parameters

https://www.typescriptlang.org/docs/handbook/generics.html#working-with-generic-type-variables

day22

Top comments (0)