definitelytyped

TypeScript Type Annotation Excluding Primitives

被刻印的时光 ゝ 提交于 2021-02-08 09:49:18
问题 The question: Is there any way to write a type annotation in TypeScript that allows any object literal, but doesn't allow built-in types number , string , boolean , Function or Array ? Why? I have been working on improving some type definitions on DefinitelyTyped for some libraries I am using on my projects at work. A common pattern I have noticed in many JS libraries is to pass an 'options' object used to configure the library or plugin. In these cases, you will often you will see type

Typescript declaration for global function

孤者浪人 提交于 2021-02-08 04:58:06
问题 I am trying to use image loading third party plugin blueimp. That plugin has global function loadImage( e.target.files[0], function (img) { document.body.appendChild(img); }, { maxWidth: 600 } ); How can I call this function using typescript? 回答1: You can put the following line before the function call: declare var loadImage; [Playground] 来源: https://stackoverflow.com/questions/34395615/typescript-declaration-for-global-function

property 'isvalid' does not exist on type 'KnockoutObservable'

时间秒杀一切 提交于 2021-01-28 15:02:17
问题 I have just started switching from javascript to typescipt. I am using knockout for obvious advantages it has to offer. I need to define a knockout computed observable which is dependent on the value of another knockout observable. Return true if the observable is valid else return false. This is how I have structured the code - class anyClass { private address: KnockoutObservable<any> = ko.observable().extend({ required : true}); private canPrintAddresses : KnockoutComputed<boolean> = ko

property 'isvalid' does not exist on type 'KnockoutObservable'

点点圈 提交于 2021-01-28 15:01:26
问题 I have just started switching from javascript to typescipt. I am using knockout for obvious advantages it has to offer. I need to define a knockout computed observable which is dependent on the value of another knockout observable. Return true if the observable is valid else return false. This is how I have structured the code - class anyClass { private address: KnockoutObservable<any> = ko.observable().extend({ required : true}); private canPrintAddresses : KnockoutComputed<boolean> = ko

Group items in Typescript with lodash

守給你的承諾、 提交于 2020-12-30 07:27:38
问题 I need to group a collection of objects by date: var meetings = [ {date:"2001-01-01 13:00", place:"park"}, {date:"2001-01-01 14:00", place:"school"}, {date:"2001-01-02 11:00", place:"house"} ]; so it becomes: var groupedMeetings = [ { day:"2001-01-01", meetings: [ {date:"2001-01-01 13:00", place:"park"}, {date:"2001-01-01 14:00", place:"school"} ] }, { day:"2001-01-02", meetings: [ {date:"2001-01-02 11:00", place:"house"} ] } ] I was able to group them with _.groupBy and _.map var g = _

Group items in Typescript with lodash

一曲冷凌霜 提交于 2020-12-30 07:26:50
问题 I need to group a collection of objects by date: var meetings = [ {date:"2001-01-01 13:00", place:"park"}, {date:"2001-01-01 14:00", place:"school"}, {date:"2001-01-02 11:00", place:"house"} ]; so it becomes: var groupedMeetings = [ { day:"2001-01-01", meetings: [ {date:"2001-01-01 13:00", place:"park"}, {date:"2001-01-01 14:00", place:"school"} ] }, { day:"2001-01-02", meetings: [ {date:"2001-01-02 11:00", place:"house"} ] } ] I was able to group them with _.groupBy and _.map var g = _

Group items in Typescript with lodash

心已入冬 提交于 2020-12-30 07:25:31
问题 I need to group a collection of objects by date: var meetings = [ {date:"2001-01-01 13:00", place:"park"}, {date:"2001-01-01 14:00", place:"school"}, {date:"2001-01-02 11:00", place:"house"} ]; so it becomes: var groupedMeetings = [ { day:"2001-01-01", meetings: [ {date:"2001-01-01 13:00", place:"park"}, {date:"2001-01-01 14:00", place:"school"} ] }, { day:"2001-01-02", meetings: [ {date:"2001-01-02 11:00", place:"house"} ] } ] I was able to group them with _.groupBy and _.map var g = _

TypeScript 新特性介绍

房东的猫 提交于 2020-12-11 17:43:49
TypeScript 字符串新特性 多行字符串 JavaScript 定义多行字符串 var word = 'aaa' + 'bbb' + 'ccc' TypeScript 定义多行字符串 var word = ` aaa bbb ccc ` 字符串模板 var myName = "Zhang San"; var getName = function() { return "zhangsan" } console.log(`hello ${myName}`); console.log(`hello ${getName()}`); 自动拆分字符串 function test(template, name, age) { console.log(template); console.log(name); console.log(age); } var myName = "Zhang san"; var getAge = function() { return 18; } test `my name is ${myName}, I'm ${getAge()}`; 参数新特性 参数类型 在参数名称后面使用冒号来制定参数的类型 声明类型 any string number booleam void (不需要返回值的函数) var myName: string = "zhang san";

How do I write the type definition for a module with a default export

╄→гoц情女王★ 提交于 2020-08-08 05:58:28
问题 I want to write a type definition for storybook-router. It needn't be that accurate, since this is a minor development tool (i.e. any s are acceptable), but I can't even seem to get that to work. What I want to represent is: import StoryRouter from 'storybook-router'; ...in which StoryRouter is a function that matches the interface StoryDecorator from @types/storybook__react . I tried the following definition file: import { StoryDecorator } from '@storybook/react'; declare type StoryRouter =

How do I use types defined by @types/redux-form in React component with Field and FieldArray?

人盡茶涼 提交于 2020-05-13 17:48:09
问题 I'm developing app with React, Redux, Redux-Form and TypeScript. I am struggling to use types defined by package @types/redux-form (DefinitelyTyped), especially with FieldArray. There is an attribute "component" where I pass reference to component, but I have no clue what type should I use when describing its props. I downloaded example of using FieldArray from Redux-Form repository and slightly modified it to work with TypeScript. I want to compile it with compilerOption "noImplicitAny":