Questions tagged [typescript2.0]

Tag for questions specific to new features in TypeScript 2.x. For general TypeScript questions, the correct tag is TypeScript.

Tag for questions specific to new features in TypeScript 2.x. For general TypeScript questions, the correct tag is .

TypeScript 2.0 documentation

1412 questions
18
votes
2 answers

Import js file with TypeScript 2.0

Abstract I'm trying to import ".js" file from an external location (i.e. node_modules) I'm trying to do this using commonjs module pattern, however import wouldn't want to work with ".js" file types until I add ".d.ts" file near ".js" file in the…
Lu4
  • 13,853
  • 12
  • 68
  • 122
17
votes
2 answers

Is there a type in @types/express for Express middleware functions

Right now I have this in a custom .d.ts file: import { Request, Response, NextFunction } from 'express'; export type MiddleWareFn = (req: Request, res: Response, next: NextFunction) => void; and I reference that file like so: router.use('/foo',…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
17
votes
1 answer

tsc - ignore errors at command line

I have this: $ tsc -m amd --outFile dist/out.js lib/index.ts lib/index.ts(87,48): error TS1005: ';' expected. Is there a command line option I can use to ignore errors?
Alexander Mills
  • 1
  • 80
  • 344
  • 642
17
votes
2 answers

TSLint - Preventing error: The key is not sorted alphabetically

I'm doing a test app with Ionic2 / Cordova / Typescript / Angular. I'm using tslint 5.6.0. I'm using the following module: https://www.npmjs.com/package/tslint Focusing on just one file... when linting the following file: import { NgModule,…
davidesp
  • 2,546
  • 6
  • 25
  • 59
17
votes
2 answers

Update Typescript in Angular2 project

I have an Angular2 project using Typescript, in Visual Studio. I want to update Typescript from 1.8 to 2.0.x. In my system I have updated typescript and tsc -v logs Version 2.0.10 The package.json, among others, contains "devDependencies": { …
Konst
  • 4,023
  • 5
  • 22
  • 35
17
votes
3 answers

Moving from typings to @types using Visual Studio & Typescript 2.0.3

I've tried to remove typings from my web project (Visual Studio 2015 Community) and install d.ts files via new NPM @types (typescript 2.0.3) in package.json: "dependencies": { "@types/angular": "^1.5.8", "@types/angular-cookies": "^1.4.2", …
16
votes
6 answers

TypeScript & runtime type-checking, simple solution in 2020

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…
brillout
  • 8,117
  • 9
  • 60
  • 74
16
votes
1 answer

Typed Generic Key Value Interface in Typescript

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': {…
Benjamin M
  • 20,265
  • 25
  • 105
  • 178
16
votes
5 answers

Typescript: Use class as interface

I tried to use an Class as Interface for another class. With this I am trying to accomplish an up-to-date mockClass for Testing. This should be possible and is an favorable approach, as state in https://angular.io/guide/styleguide#interfaces And is…
jvoigt
  • 1,418
  • 1
  • 13
  • 18
16
votes
2 answers

JSX element type 'App' is not a constructor function for JSX elements. Types of property 'setState' are incompatible

I am using the Microsoft TypeScript-React-Starter and got this compile error during npm start: ./src/index.tsx (16,5): error TS2605: JSX element type 'App' is not a constructor function for JSX elements. Types of property 'setState' are…
Zening Qu
  • 3,133
  • 8
  • 35
  • 65
16
votes
2 answers

TS - Only a void function can be called with the 'new' keyword

I am getting this weird error from TypeScript: "Only a void function can be called with the 'new' keyword." What? The constructor function, just looks like: function Suman(obj: ISumanInputs): void { const projectRoot = _suman.projectRoot; …
Alexander Mills
  • 1
  • 80
  • 344
  • 642
16
votes
2 answers

TypeScript multiple return types with identical parameters

Background Trying to get into the spirit of TypeScript, I am writing fully typed signatures in my Components and Services, which extends to my custom validation functions for angular2 forms. I know that I can overload a function signature, but this…
msanford
  • 10,127
  • 8
  • 56
  • 83
15
votes
1 answer

How to merge multiple typescript definitions file into a single file with one module

Anyone know if there is any tool that will merge multiple Typescript definition files (.d.ts) into a single .d.ts file with all the declarations merged therein under a single declared module? Or is this typically done manually (which would be…
Doug Kent
  • 737
  • 1
  • 8
  • 17
15
votes
3 answers

How to import external type into global .d.ts file

I'm using Moment.js to handle datetime objects in my TypeScript project. I would like to define an object type that has a key with a value of a type Moment. However, when I add the following to a global definition file (test.d.ts), none of the…
keawade
  • 153
  • 1
  • 2
  • 7
15
votes
4 answers

find sum of Boolean values JavaScript object array

Hi i am trying to find the sum of Boolean values in the object array in JavaScript My json like be var myoBj = [{ "id": 1, "day": 1, "status": true }, { "id": 2, "day": 1, "status": false }, { "id": 3, "day": 1, "status":…