typescript2.0

TypeScript - what type is f.e. setInterval

拥有回忆 提交于 2021-01-26 03:15:54
问题 If I'd like to assign a type to a variable that will later be assigned a setInterval like so: this.autoSaveInterval = setInterval(function(){ if(this.car.id){ this.save(); } else{ this.create(); } }.bind(this), 50000); What type should be assigned to this.autosaveInterval vairable? 回答1: The type is number; private autoSaveInterval: number = setInterval( ()=>{console.log('123')},5000); 回答2: The type depends on which function you are going to use there are 2 overloads, the return type is marked

TypeScript - what type is f.e. setInterval

本小妞迷上赌 提交于 2021-01-26 03:14:53
问题 If I'd like to assign a type to a variable that will later be assigned a setInterval like so: this.autoSaveInterval = setInterval(function(){ if(this.car.id){ this.save(); } else{ this.create(); } }.bind(this), 50000); What type should be assigned to this.autosaveInterval vairable? 回答1: The type is number; private autoSaveInterval: number = setInterval( ()=>{console.log('123')},5000); 回答2: The type depends on which function you are going to use there are 2 overloads, the return type is marked

TypeScript - what type is f.e. setInterval

女生的网名这么多〃 提交于 2021-01-26 03:14:09
问题 If I'd like to assign a type to a variable that will later be assigned a setInterval like so: this.autoSaveInterval = setInterval(function(){ if(this.car.id){ this.save(); } else{ this.create(); } }.bind(this), 50000); What type should be assigned to this.autosaveInterval vairable? 回答1: The type is number; private autoSaveInterval: number = setInterval( ()=>{console.log('123')},5000); 回答2: The type depends on which function you are going to use there are 2 overloads, the return type is marked

How to bind JSON object key value pair separately to angular template

喜欢而已 提交于 2021-01-24 14:02:31
问题 And i have a dynamic json coming from an API as below: {123: "Mumbai", 456: "Bangalore", 789: "Chennai", 101: "Andhra",...} I have below HTML code written in my template in which I am getting image-1, image-2 logos from my assets folder <div class="row"> <div class="col-6" (click)="cityClick('Bangalore')"> <div class="img-1"> // my image-1 logo goes here </div> <div class="img-text"> Bangalore </div> </div> <div class="col-6" col-6 (click)="cityClick('Mumbai')"> <div id="image_block" class=

Typed Generic Key Value Interface in Typescript

混江龙づ霸主 提交于 2020-12-29 06:09:10
问题 I have the following example Object: let foo: Foo = { 'key1': { default: 'foo', fn: (val:string) => val }, 'key2': { default: 42, fn: (val:number) => val }, // this should throw an error, because type of default and fn don't match 'key3': { default: true, fn: (val:string) => val } } The Interface should look something like this: interface Foo { [key: string]: { default: T, fn: (val:T) => any } } This of course doesn't work, because there's no T defined. So I thought about doing this:

TypeScript & runtime type-checking, simple solution in 2020 [closed]

时光怂恿深爱的人放手 提交于 2020-11-27 04:55:53
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last month . Improve this question As we all know, TypeScript type-checks only at compile-time. There are couple of existing approaches to add runtime checks, such as io-ts, but I'm left to wonder if there is a simpler way. For example a Babel plugin that would transpile this: type Todo = { userId: