Linked Questions

0 votes
2 answers
861 views

Lets say I have an interface: // I get this from an external library so I have no control over it interface Balloon { diameter: number; color: "red" | "blue" | "green"...
tvanbeek's user avatar
  • 132
-1 votes
1 answer
274 views

How can I reuse the type of someMethod ? Interface Foo { someMethod: // want to reuse this type without copy pasting } const myValue: // I want it to be of type Foo.someMethod
Lev's user avatar
  • 16k
0 votes
1 answer
166 views

How to create a type that refer to a type of an interface's fields? Here is what I want to achieve: interface SomeOption { readonly name: string; readonly value: number; } type OptionName = ...
eXception's user avatar
  • 2,457
0 votes
1 answer
107 views

I want to get a "postType" Property from an interface defined like this export interface PostType { postType: { title?: string; content?: string; }; } The purpose I want to take out and ...
dsfdsf2fafad's user avatar
0 votes
0 answers
72 views

Say, I have this interface: interface MyObject { all: string[] | {[value: string]: string} some: string[] } In my code I have an object of this type which I deconstruct, and then use one of the ...
artooras's user avatar
  • 6,905
0 votes
0 answers
45 views

Given an interface like this: interface Person { name: Some | Pretty | Complex | Type; age: number; } I'd like to get the type of a specific key, e.g. name. So I could e.g. write a function like (...
Rene Saarsoo's user avatar
0 votes
0 answers
30 views

So let's say I have a type Foo defined as: type Foo = { bar: string; xxx: { abc: string; def: number; }; }; How do I extract the type of my property xxx to define let's ...
Ruben Serrate's user avatar
328 votes
10 answers
677k views

I have a variable. abc:number|string; How can I check its type? I want to do something like below: if (abc.type === "number") { // do something }
Hongbo Miao's user avatar
  • 50.8k
17 votes
2 answers
8k views

Is there any way to declare a variable with the type of another variable? For instance, I declare a class member with some type, and then later I want to declare another variable in a function of the ...
zacaj's user avatar
  • 2,128
0 votes
1 answer
3k views

I want to extract a type from my an interface by it's property name to reuse in a Record. I am having difficulties with syntax to retrieve the type by property name. I am trying to make it a bit more ...
LazioTibijczyk's user avatar
0 votes
2 answers
633 views

How to cast geometryType as I get this error : IShape is a Type not a Namespace for interface IShape { readonly geometryType: "RECTANGLE" | "SQUARE" } let geometryType =...
user310291's user avatar
  • 38.7k
3 votes
0 answers
478 views

Let's say I have an interface interface Test { a: string; b: string; c: 'x' | 'y' | 'z'; } How do I construct an object type which requires all the keys of the c union type? Record<...
Amjad sibili's user avatar
  • 1,237
2 votes
1 answer
195 views

class A { public static readonly TYPE = "A"; } interface forA { for: A.TYPE } As you can see, I'm trying to access A.TYPE from forA, so that I can do a form of type guarding. But, I'm ...
Tobiq's user avatar
  • 2,697
2 votes
1 answer
206 views

If I have an interface defined for a function component, say MyFuncComp.tsx import React from 'react' interface MyFuncCompProps { x: string y: number z: Array<ComplexType> } export ...
Chiranjib's user avatar
  • 1,803
0 votes
1 answer
73 views

I would like to get the of the return type from a method where I pass the key as a parameter and the return is type from the interface. I looked at this answer Is there a way to "extract" ...
Get Off My Lawn's user avatar

15 30 50 per page