Questions tagged [typescript2.2]

Use this tag for questions specific to new features in TypeScript 2.2. For general TypeScript questions, the correct tag is TypeScript.

Use this tag for questions specific to new features in TypeScript 2.2. For general TypeScript questions, the correct tag is .

TypeScript 2.2 documentation

52 questions
25
votes
1 answer

Importing nodejs `fs` with typescript when executing with ts-node?

I'm trying to run the following code with ts-node. import { writeFileSync, readFileSync } from 'fs'; However I get: src/main/ts/create.ts (1,45): Cannot find module 'fs'. (2307) What do I need to do in to allow typescript to import the fs module?
Ole
  • 29,797
  • 32
  • 110
  • 232
19
votes
5 answers

Import module from root path in TypeScript

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…
user7536774
14
votes
2 answers

error TS2345: Argument of type 'T' is not assignable to parameter of type 'object'

The code below was working fine with TypeScript 2.1.6: function create(prototype: T, pojo: Object): T { // ... return Object.create(prototype, descriptors) as T; } After updating to TypeScript 2.2.1, I am getting the following…
Nenad
  • 19,511
  • 8
  • 58
  • 80
13
votes
1 answer

Typescript return value wrapped in curly braces?

In the following code block heros is wrapped with curly braces: export class InMemoryDataService implements InMemoryDbService { createDb() { let heroes = [ {id: 11, name: 'Mr. Nice'}, {id: 12, name: 'Narco'}, …
Ole
  • 29,797
  • 32
  • 110
  • 232
12
votes
1 answer

How to install TypeScript 2.2 onto Visual Studio 2017

Some people in our team have both Visual Studio 2015 and Visual Studio 2017 installed. Others only have the latest Visual Studio 2017 (15.5). With the latter, we noticed that our TypeScript project in the IDE is generating all kinds of unexpected…
7
votes
1 answer

typescript 2.2 interfaces extend object type

I have function using an object as parameter like this: interface Options { foo?: string; bar?: number; }; function fooNction(opts: Options): void { } This works fine in some cases but not all: fooNction({foo: "s"}); // OK fooNction({a:…
Flarna
  • 93
  • 1
  • 5
6
votes
2 answers

Typescript Error: Property 'append' does not exist on type 'HTMLElement'

The Problem: I'm receiving a Typescript 2.2.1 compilation error when trying to append a compiled angular 1.5 template to an existing HTMLElement. Code: $document.find(scope.target)[0].append($compile(menu)(scope)[0]); Compile error: [ts] Property…
Zengineer
  • 508
  • 1
  • 7
  • 19
6
votes
1 answer

Pass array to async library eachSeries - expects 'Dictionary<{}>'

I have the following TypeScript code: const allDescribeBlocks: Array = suman.allDescribeBlocks; async.eachSeries(allDescribeBlocks, function (block: ITestSuite, cb: Function) { //.... }, cb); this will transpile with…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
4
votes
0 answers

Using commonjs modules in Angular4 services?

I first tested using the commonjs module that I installed like this: npm install the-module; I then created main.js which looked something like this: var module = require('the-module'); module.doStuff(); Then compiled main.js with webpack into…
Ole
  • 29,797
  • 32
  • 110
  • 232
4
votes
1 answer

Linking data fields with discriminated unions causing errors

I'm working on an Ionic (3.0.0) app, and frequently want to link the types of two fields in a data interface. For example, a NotificationData has verb: 'mention' | 'share' | ... and reference: ProfileReference | DocumentReference | ... fields, but…
4
votes
0 answers

How to bundle typescript-node-express application

I want to build a complete fullstack web app. My server side code is in typescript. I would like to configure my project such that it will be from the following structre: projectFolder/src/(server-side typescript files) - contians an index.ts main…
3
votes
1 answer

Publishing Typescript 2.3 Modules to NPM for Angular 4 Consumption

There are related instructions in Writing NPM modules in Typescript , however it's dated and there are now a lot of different answers which may or may not work for Angular. There's also a very good presentation by Jason Aden on youtube on how to…
Ole
  • 29,797
  • 32
  • 110
  • 232
3
votes
1 answer

What are typescript `--lib` library files?

There is a similar question. That covers what typescript does with the option. The below question and answer covers where the lib files come from at runtime. When I looked up the description for the --lib compiler option it says: List of library…
Ole
  • 29,797
  • 32
  • 110
  • 232
3
votes
2 answers

Is it possible to pass Typescript decorator object values in at runtime?

I have a class that is decorated with a @MinDate constraint like this: export default class Order { purchaseDate: Date; @MinDate(this.purchaseDate) receiptDate: Date; } When attempting to validate an instance of Order that is valid the…
Ole
  • 29,797
  • 32
  • 110
  • 232
3
votes
2 answers

Adding property to function with TypeScript

Say I have a function expression called run: let run = function(){ }; I want to add a property called "default" to this run function, a reference to itself. run.default = run; this is to support multiple module export formats in JS. I hear the…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
1
2 3 4