typescript2.1

Having error “Module 'name' resolves to an untyped module at…” when writing custom TypeScript definition file

血红的双手。 提交于 2019-12-31 08:53:49
问题 I can't find TypeScript definition @type/{name} for one of my installed NodeJS packages, so I attempt to write a d.ts file for it, and put the file in {project root}\typings folder. This is how I do: // My source code: index.ts import Helper from 'node-helper-lib'; // My definition: \typings\node-helper-lib.d.ts declare....(something else) declare module 'node-helper-lib' { class Helper { ... } export = Helper; } However, Visual Studio Code keeps yielding this error and puts red line under

Having error “Module 'name' resolves to an untyped module at…” when writing custom TypeScript definition file

我是研究僧i 提交于 2019-12-31 08:53:30
问题 I can't find TypeScript definition @type/{name} for one of my installed NodeJS packages, so I attempt to write a d.ts file for it, and put the file in {project root}\typings folder. This is how I do: // My source code: index.ts import Helper from 'node-helper-lib'; // My definition: \typings\node-helper-lib.d.ts declare....(something else) declare module 'node-helper-lib' { class Helper { ... } export = Helper; } However, Visual Studio Code keeps yielding this error and puts red line under

Navigation Error in angular2

倖福魔咒の 提交于 2019-12-29 11:48:09
问题 I have updated the angular packages version from 2.4.10 to 4.0.0 after updating i am getting the following errors while navigating. ERROR Error: Uncaught (in promise): Error: Found the synthetic property @transformPlaceholder. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. Error: Found the synthetic property @transformPlaceholder. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application And i changed the

Typescript 2.1.5 Function calls are not supported

醉酒当歌 提交于 2019-12-23 20:15:49
问题 I have the following ngrx reducer function export const raceReducer: ActionReducer<IRace> = ( state: IRace = new Race(), action?: Action ) => { switch ( action.type ) { case RaceActions.ADD_OLP: return ngrxStateUpdater( state, action ) default: return state; } }; Running the application gives the following error: ERROR in Error encountered resolving symbol values statically. Function calls are not s upported. Consider replacing the function or lambda with a reference to an exported fun ction

Observable.zip is not a function

吃可爱长大的小学妹 提交于 2019-12-23 07:22:41
问题 VM95422:27 ORIGINAL EXCEPTION: WEBPACK_IMPORTED_MODULE_3_rxjs_Observable .Observable.zip is not a function Tried various imports // import 'rxjs/add/operator/zip'; // import 'rxjs/add/observable/zip-static'; // import 'rxjs/add/operator/zip'; import 'rxjs/operator/zip'; Trying to use it like that: const zippedUsers: Observable<User[]> = Observable.zip<User>(this.usersObservable); Angular 4, TypeScript 2.1.6 package.json: "rxjs": "^5.1.0", 回答1: maybe something like import {Observable} from

Is there any way to target the plain JavaScript object type in TypeScript?

你离开我真会死。 提交于 2019-12-13 12:04:43
问题 I'm trying to write a function where I'd like to indicate that it returns some kind of plain JavaScript object. The object's signature is unknown, and not interesting for now, only the fact that it's a plain object. I mean a plain object which satisfies for example jQuery's isPlainObject function. For example { a: 1, b: "b" } is a plain object, but var obj = new MyClass(); is not a "plain" object, as its constructor is not Object . jQuery does some more precise job in $.isPlainObject , but

Typescript: subclass/extend of Promise gives 'TypeError: undefined is not a promise' on run time

纵饮孤独 提交于 2019-12-12 04:36:53
问题 I'm trying to cancel my async method call in Typescript. To do this, I have created a new Promise type, which inherits from Promise : class CancelablePromise<T> extends Promise<T>{ public cancelMethod: () => void; constructor(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) { super(executor); // Set the prototype explicitly. Object.setPrototypeOf(this, CancelablePromise.prototype); } //cancel the operation public cancel() { if (this

Import module from root path in TypeScript

江枫思渺然 提交于 2019-12-08 15:40:36
问题 Let's suppose I've a project, and its main source directory is: C:\product\src Based on this directory, every import path would be relative to it. I.e., suppose: // Current script: C:\product\src\com\name\product\blah.ts import { thing } from '/com/name/product/thing'; same as: // Current script: C:\product\src\com\name\product\blah.ts import { thing } from '../../../com/name/product/thing'; My entry compilation file would be at: C:\product\src for instance. So, is there a way to specify this

Why does the new `Pick<T, K extends keyof T>` type allow subsets of `K` in React's `setState()`?

自作多情 提交于 2019-12-06 02:03:43
问题 I thought I understood the purpose of the new TS 2.1 Pick type, but then I saw how it was being used in the React type definitions and I don't understand: declare class Component<S> { setState<K extends keyof S>(state: Pick<S, K>, callback?: () => any): void; state: Readonly<S>; } Which allows you to do this: interface PersonProps { name: string; age: number; } class Person extends Component<{}, PersonProps> { test() { this.setState({ age: 123 }); } } My confusion here is that keyof S is {

Typescript: subclass/extend of Promise: does not refer to a Promise-compatible constructor value

折月煮酒 提交于 2019-12-05 00:59:12
问题 I'm trying to cancel my async method call in Typescript. To do this, I have created a new Promise type, which inherits from Promise : class CancelablePromise<T> extends Promise<T>{ private cancelMethod: () => void; constructor(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, cancelMethod: () => void) { super(executor); this.cancelMethod = cancelMethod; } //cancel the operation public cancel() { if (this.cancelMethod) { this.cancelMethod(); } }