Top "Typescript-generics" questions

For questions related specifically to usage of generic types in Typescript.

Object index key type in Typescript

I defined my generic type as interface IDictionary<TValue> { [key: string|number]: TValue; } But TSLint's complaining. How am …

typescript typescript-generics
How to fix TS2322: "could be instantiated with a different subtype of constraint 'object'"?

A have a type-check error in recursive types. I am trying to write types for react-jss styles object. type StylesFn&…

typescript typescript-generics
Can You Specify Multiple Type Constraints For TypeScript Generics

I have a generic interface like this example with a single type constraint: export interface IExample<T extends MyClass&…

typescript typescript-generics
Declare a component with generic type

Is it possible to declare a component with a generic type in Angular 4? The following code causes build errors: export …

angular typescript angular-components typescript-generics
Typed Generic Key Value Interface in Typescript

I have the following example Object: let foo: Foo = { 'key1': { default: 'foo', fn: (val:string) => val }, 'key2': { …

typescript generics type-inference typescript2.0 typescript-generics
TypeScript Generics: 'type is not assignable to type T'

I have made a factory that will create instances of certain classes. I want to use generics to ensure that …

typescript typescript-generics
Typescript check generic type for interface

In my angular 6 file I've got an interface defined and then in a method that takes a generic parameter, T, …

typescript typescript-generics
How to create a new object of type 'T' in generic class in typescript?

I have the following service @Injectable() export class CollectionService<T> { constructor(protected http: Http) {} factory<T>(…

angular typescript angular2-services typescript-generics
How to build a type from enum values in TypeScript?

Given the following: enum FooKeys { FOO = 'foo', BAR = 'bar', } I'd like to make an interface like this one, but instead …

typescript types typescript-generics
In TypeScript, how to get the keys of an object type whose values are of a given type?

I've been trying to create a type that consists of the keys of type T whose values are strings. In …

typescript generics typescript-generics mapped-types