typescript1.5

Adding existing functions in TypeScript: Node.getAttribute()

跟風遠走 提交于 2021-02-11 15:20:46
问题 What is the best way to add a function to typescript that actually exists already? In my case this is Node.getAttribute() , which is actually built-in to the browser, but not yet recognized by TypeScript. It errors: Cannot find property 'getAttribute' on type 'Node'. In my case I ran into this error executing the following: var xmlDocument = new DOMParser().parseFromString(xmlString, "text/xml"), rootfile = xmlDocument.getElementsByTagName("aNode")[0]; console.log(rootfile.getAttribute(

Can I define a Typescript class which has an index signature?

ε祈祈猫儿з 提交于 2020-03-18 10:27:16
问题 I have an interface type called IRawParams which simply specifies a string key and any vals. interface IRawParams { [key: string]: any } I have a class, ParamValues which contains some behavior on top of keys/values. I'd like to specify that the ParamValues class implements IRawParams interface. class ParamValues implements IRawParams { parseFromUrl(urlString: string) { Parser.parse(urlString).forEach(item => this[item.key] = item.val); } } // so I can do something like this var params = new

Can I define a Typescript class which has an index signature?

烈酒焚心 提交于 2020-03-18 10:25:02
问题 I have an interface type called IRawParams which simply specifies a string key and any vals. interface IRawParams { [key: string]: any } I have a class, ParamValues which contains some behavior on top of keys/values. I'd like to specify that the ParamValues class implements IRawParams interface. class ParamValues implements IRawParams { parseFromUrl(urlString: string) { Parser.parse(urlString).forEach(item => this[item.key] = item.val); } } // so I can do something like this var params = new

How do I set the TypeScript compiler version for an ASP.NET 5 MVC 6 project in Visual Studio 2015 RC?

℡╲_俬逩灬. 提交于 2020-01-13 10:54:28
问题 So I'm now at my witts end with this one. As the question in the title asks, I'm trying to set the tsc version for a sample ASP.NET 5 MVC 6 project. I'm using Visual Studio 2015 RC and I want to compile TypeScript using version 1.5 Beta that was recently released. In VS 2013, this was an option page in the project properties. I thought there would be some magic project.json value I could set, but nope. If I could even turn off the compilation (version 1.4) and use a Gulp task, even that would

Module '“angular2/angular2”' has no exported member 'For'

僤鯓⒐⒋嵵緔 提交于 2019-12-30 06:29:32
问题 I am following the tutorial on the official Angular2 website. https://angular.io/docs/js/latest/guide/displaying-data.html Here is my .ts file: /// <reference path="typings/angular2/angular2.d.ts" /> import {Component, View, bootstrap, For} from 'angular2/angular2'; @Component({ selector: 'display' }) @View({ template: '<p>name: {{myName}}</p>' + '<p>Friends:</p>' + '<ul>'+ '<li *for="#name of names">'+ '{{name}}'+ '<li>'+ '<ul>', directives: [For] }) class DisplayComponent{ myName: string;

How to extend the 'Window' typescript interface

元气小坏坏 提交于 2019-12-30 00:52:09
问题 In my example, I'm trying to extend the TS Window interface to include a polyfill for fetch . Why doesn't matter. The question is " how do I tell TS that window.fetch is a valid function? " I'm doing this in VS Code, v.0.3.0 which is running TS v.1.5 (IIRC). Declaring the interface inside my TS class file where I want to use it doesn't work: ///<reference path="typings/tsd.d.ts"/> interface Window { fetch:(url: string, options?: {}) => Promise<any> } ... window.fetch('/blah').then(...); // TS

Injectables not working in angular 2.0

陌路散爱 提交于 2019-12-29 07:26:08
问题 I recently started playing with Angular2 . I've been trying to get injectables to work for about half a day now, but I still can't figure out what I'm doing wrong. To keep it as simple as possible, I copied code from 5 Min Quickstart in the official webpage. Demo itself works fine, but when i try to use injectables, I get an error saying ORIGINAL ERROR: Cannot resolve all parameters for MyAppComponent. Make sure they all have valid type or annotations. My typescript file /// <reference path=

Unable to concat typescript modules (.ts) files into single output(.js) using --out Comment: Getting Error

有些话、适合烂在心里 提交于 2019-12-25 04:15:57
问题 I am new to Typescript. I've been trying to concatenate typescript modules by using the tsc --out command. But I'm getting some error. There is no information about the error. Below is the process, I've tired. .ts files I have: Validation.ts: module Validation { export interface StringValidator { isAcceptable(s: string): boolean; } } ZipCodeValidator.ts: /// <reference path="Validation.ts" /> module Validation { var numberRegexp = /^[0‐9]+$/; export class ZipCodeValidator implements

TypeScript 1.5 ES6 modules & .d.ts files from DefinitelyTyped seem incompatible

别来无恙 提交于 2019-12-24 17:15:09
问题 I'm using WebStorm for web-development & have recently upgraded from the built-in TypeScript 1.4 compiler to 1.5.3. However, not everything went as I wanted as the compiler began to yield errors prompting me to drop the --module commonjs parameter & switch to ES6 modules instead (I'm using --target es6 ). Having done that, I started getting errors saying that import assignments cannot be used when targeting ES6 & that I should use the new module syntax instead (error 1202). So I converted all

TypeScript 1.5 ES6 modules & .d.ts files from DefinitelyTyped seem incompatible

不打扰是莪最后的温柔 提交于 2019-12-24 17:14:31
问题 I'm using WebStorm for web-development & have recently upgraded from the built-in TypeScript 1.4 compiler to 1.5.3. However, not everything went as I wanted as the compiler began to yield errors prompting me to drop the --module commonjs parameter & switch to ES6 modules instead (I'm using --target es6 ). Having done that, I started getting errors saying that import assignments cannot be used when targeting ES6 & that I should use the new module syntax instead (error 1202). So I converted all