w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » TYPESCRIPT » Page 1
typescript 1.3 sometimes giving false type mis-match errors
I've had the exact same issue when I updated to 1.3, after digging for quite some time I've come across the answer. The 1.3 compiler apparently doesn't like relative paths, so you must use only absolute paths for all compiler arguments. The problem specifically for me was the $FileName$ (relative path) macro in the TypeScript file watcher arguments. Changing it to $FilePath$ (absolute path) fixe

Categories : Typescript

How to include ambient module declarations inside another ambient module?
Ambient external modules cannot be nested in other modules. Using an import or export at the root of a file creates a file module. That explains the error nested module. Fix: Import inside and not at the root of the file: /// <reference path="../node_modules/immutable/dist/immutable.d.ts" /> declare module 'morearty' { import I = require('immutable'); }

Categories : Typescript

What means "ambient" in TypeScript
Ambience : the character and atmosphere of a place.. TypeScript declaration files exist to tell the compiler of the environment in which it is running. Hence the word ambient context. You can only do declarations in a declaration context and not implementations. PS: Ambient declaration covered here.

Categories : Typescript

How to write an interface represents a tuple type in TypeScript?
You can not create an interface from a Tuple, like you can not make one from a string either. You can use a Tuple in an interface like: interface IDATA { value: [number, string]; }

Categories : Typescript

Circular dependency issue with Typescript, CommonJS & Browserify
Simply put (perhaps simplistically, but I don't think so), if you have ModuleA and ModuleB and both rely on each other, they aren't modules. They are in separate files, but they are not acting like modules. In your situation, the classes are highly interdependent, you can't use any one of those classes without needing them all, so unless you can refactor the program to try an make the dependencie

Categories : Typescript

Do private properties and methods belong inside a TypeScript definition file?
It depends on the JavaScript implementation, I would avoid exposing private members that are not on the prototype. Say we have the following JavaScript: var Example = (function () { var update = function() { alert('Private'); } function Example() { } Example.prototype.doIt = function () { update(); }; return Example; })(); If I declare it like this

Categories : Typescript

How to require a specific string in TypeScript interface
This isn't supported yet, but it's being investigated (using the exact syntax you have there). See https://github.com/Microsoft/TypeScript/issues/1003 in the TypeScript GitHub project.

Categories : Typescript

TypeScript declaring namespaced external module?
The exported item can be declared as a variable, with the appropriate type annotation. Here is an example (although I'm not sure exactly what you want to export)... // foo/bar.d.ts interface FooBar { baz: () => void; } declare module foo { export var bar: FooBar; } declare module "foo/bar" { export = fb; }; declare var fb: FooBar; This results in a global variable fb and a

Categories : Typescript

Typescript from 1.0.0 to 1.1.0-1 - Error TS2411
You need to use the matching lib.d.ts that comes with tsc.js. It looks like you're using some custom lib.d.ts from some other path (app/lib/def ?).

Categories : Typescript

Is there a way to create nominal types in TypeScript that extend primitive types?
There isn't a way to do this. A suggestion tracking this on the GitHub site is Units of Measure. In a future release, you'll be able to use type to define alternate names for the primitives, but these will not have any checking associated with them: type lat = number; type lon = number; var x: lat = 43; var y: lon = 48; y = 'hello'; // error x = y; // No error

Categories : Typescript

cannot write an angular ui typeahed handler with typescript
found the solution, I have to return the promise object itself changing it in public updateQuartieri = (typed: string) => { var filtro: Factories.filtroRicercaQuartieri = new Factories.filtroRicercaQuartieri(); filtro.testo = typed; filtro.idComune = this.censimento.comuneId; var ultimiPromise = this.censimentoFactory.quartieriComune(filtro); return ultimiPromise; }

Categories : Typescript

Defining custom events for TypeScript API
I assume you would like to implement a simple Observer pattern. Then, code is quite simple: Notifier: class Notifier { private _subscribers : Array<ISubscriber>; constructor() { this._subscribers = new Array<ISubscriber>(); } subscribe(o : ISubscriber) : void { this._subscribers.push(o); } myMethod() : void { // Trigger this method whenever you wish fo

Categories : Typescript

Defining prototype property in TypeScript
Yes, if you are targeting ECMAScript5 or above then you can use the following property syntax on a class class A { private internalId: number = 1; get attributeId() { return this.internalId; } set attributeId(newVal) { this.internalId = newVal; } }

Categories : Typescript

What type is a constructor?
Because TypeScript can't know what possible string may be passed to ThingPlease it can't determine the type. You need to give it a hint using a type assertion: var ctor = <typeof Thing>things[thing]; Full example below: class Thing { static ReleventInfo: string } class Foo extends Thing { } class Bar extends Thing { } class Baz extends Thing { } var things = { foo: Foo, ba

Categories : Typescript

How to get .js and .js.map files rolling to be sub files under .ts file
To fix I needed to open NewOld.ts and add a variable and then delete it which I assume kicks off the .ts watcher which corrects the issue. After running you can see the files are now nested:

Categories : Typescript

Problems running tests with Chutzpah when I use the Chutzpah.json file
UPDATED ANSWER I update the answer based on the full repro given. The original answer is preserved below. The issue is that by default chutzpah will set the sourcedirectory to look for generated scripts to the location of the chutzpah.json file. Setting it to be a parent of both your source and test folders fixes the issue { "Compile": { "Mode": "External", "Extensions":

Categories : Typescript

Copy module function declarations to global namespace
There isn't a way to "bulk" copy members into the global namespace (thankfully?), but you can use import instead of var and should get JSDoc information assuming your editor uses the TypeScript Language service:

Categories : Typescript

How do I install TypeScript 1.1 CTP from source?
The source on github doesn't contain the code for tsc.exe or the Visual Studio plugin. When you run jake local It does generate a tsc.js (among other files) in the built/local folder which is actually kind of the same. you can run it with node tsc.js and you will see the same help output you would get when calling tsc.exe.

Categories : Typescript

Why might my typescript tests fail when I run with Chutzpah using PhantomJS
Two things. First itt sounds like you are using the legacy compilation mode in Chutzpah. That mode is no-recommended since it uses a fixed version of TypeScript to compile the JS. You should use the recommended Compile settings. Second, if it is working in the browser and not in Phantom and Chutzpah is compiling both then it is probably not a typescript issues. If you run chutzpah from the com

Categories : Typescript

Typedef in TypeScript error: 'expected variableDeclarator'
Your code fragment looks fine. If this function is made to return a string, it compiles in tsc without an error. Are you sure the return value is a string? This excerpt is from the tslint repo: typedef enforces type definitions to exist. Rule options: "callSignature" checks return type of functions "indexSignature" checks index type specifier of indexers "parameter" checks type specifier of

Categories : Typescript

extending interface with generic in typescript
Interface IPropertiesToAdd defines a type variable T that is used to extend an interface named T. This is not possible. An interface can not be referred using a variable name; it must have a fixed name, e.g. Evnt: interface Evnt<T> { name: T; } interface IPropertiesToAdd<T> extends Evnt<T> { on(): void; off(): void; } I am not sure what you are trying to achieve in your

Categories : Typescript

Basic Typescript, external define
Found it, courtesy of https://www.stevefenton.co.uk/Content/Blog/Date/201301/Blog/Complex-TypeScript-Definitions-Made-Easy/ declare module CompanyName { export class TypeB { static SomeData: Date; } }

Categories : Typescript

How to completely uninstall all versions TypeScript
TypeScript is built into both VS 2013 Update 2 the VS 14 CTP and cannot be separately uninstalled. You could uninstall both of those versions of Visual Studio if it is somehow critical to remove those folders.

Categories : Typescript

TypeScript class with same name as interface
I believe there is no special keyword to access the global namespace, but the following works: // Create alias (reference) to the global Date object var OriginalDate = Date; // Make copy of global Date interface interface OriginalDate extends Date {} module Foo { export class Date { public d: OriginalDate; // <-- use alias of interface here constructor() { thi

Categories : Typescript

Chutzpah configuration for running TypeScript tests in both Visual Studio and Visual Studio Online build
I don't know if this answer is still relevant to you but it can also be useful for others. Well lets start with TypeScript and VSO. Ideally you only want your TypeScript files checked in into VSO. VSO needs to build the TypeScript to JavaScript, which can be simply achieved by just adding a Visual Studio Build step of the according project. Note that projects that contain TypeScript also got addit

Categories : Typescript

How can I use typescript in Aptana Studio?
Does anybody use TypeScript in Aptana Studio? Since its based on eclipse just use https://github.com/palantir/eclipse-typescript

Categories : Typescript

Exporting typescript function "lacks a call signature"
TypeScript doesn't parse module.exports assignments for type information. Instead of this line: module.exports = listenRestRoutes; Use this export = listenRestRoute;

Categories : Typescript

How can I type an Object coming from a .forEach function?
There are a couple of problems here: you can't short circuit a forEach and the elem var within the forEach is not assessable outside of the loop. One solution is the following: elem = (arr : any[], property, num) => { var found = null; arr.forEach(function (elem, index) { if (elem[property] === num) { found = elem; } })

Categories : Typescript

What should we use between type or interface?
You should almost always use boolean instead of Boolean. The lower-case versions boolean, number, and string refer to the JavaScript primitive types of the same name. These are the types you get from normal expressions like true, 1 + 1, or "hello". The upper-case versions Boolean, Number, and String refer to the object versions of those same types. You only get objects like this if you try hard,

Categories : Typescript

TypeScript - When to use target version?
Array.prototype.reduce is an API. The TypeScript compiler provides no API. A TypeScript developer needs to know JavaScript and its API. In the same way as CoffeeScript: "It's just JavaScript". For example, in a TS code, the API Array.prototype.reduce can be used, then the code converted to the ES3 syntax. It will work on IE8 with es5-shim.

Categories : Typescript

Type reference cannot refer to container
TypEcsPlugin Issue]1 According to the authors of the plugin I am using they are working on supporting a newer version of the compiler. Since this compile issues doesn't seem to be an issue when I use webstorm I believe the issue must be that this older typescript compiler.

Categories : Typescript

A typescript Guid class?
There is an implementation in my TypeScript utilities based on JavaScript GUID generators. Here is the code: class Guid { static newGuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); } } // Example of a bunch of GUIDs for (

Categories : Typescript

Why do specialised overload signatures work only with methods but not properties?
Support for union types is on the Typescript roadmap for the 1.4 release. See the ticket for the discussion, but it would allow a property to be declared like this: interface Test2 { propertyFoo : string | number; } It wouldn't make sense to "overload" a property as in your example, as "bar" is already a string. With a function, the return type may differ depending on the specific argument,

Categories : Typescript

Typescript: constants in an interface
You cannot declare values in an interface. You can declare values in a module: module OlympicMedal { export var GOLD = "Gold"; export var SILVER = "Silver"; } In an upcoming release of TypeScript, you will be able to use const: module OlympicMedal { export const GOLD = "Gold"; export const SILVER = "Silver"; } OlympicMedal.GOLD = 'Bronze'; // Error

Categories : Typescript

Can I cast the output of a function with typescript?
Casting can be done like this: <IUserTestDataMap>{} This casting operator does nothing other than tell the compiler "trust me, this object should be treated in the following as if it was of the specified type". interface Foo { id: number; } var x : Foo; x = {}; // error x = <Foo>{}; // okay var y = {}; x = <Foo>y; // okay

Categories : Typescript

Typescript remote debugging
With the Chrome developer tools you can add the source maps. When you open the source file, right click on the content and click "Add source maps". Versions need to match offcourse or you will get some very weird stuff when stepping through the code. See screenshot

Categories : Typescript

how can I extend an existing class in typescript
Unless you have the api source in TypeScript you can't directly inherit from the class. What you can do however, is just extend it with Javascript as described in the article. If you have TypeScript interfaces defined for those types you can extend them by just creating another interface with the same name and adding your methods.

Categories : Typescript

TypeScript - how to type a self-instantiating function
Maybe your example is simplified, and you are trying to achieve something more complex under the hood, but If i understand your code correctly you just want to return an instance of the Register function without the New operator. The only option i can think of is to trick the TS compiler, and to specify the return type as void, and then in your variables use type any. module Register { exp

Categories : Typescript

typescript / jscript side-by-side in Visual Studio 2013 update 3
You might need to enable it in the Web Essentials options. Tools --> Options and choose Web Essentials and TypeScript on the left side Screenshot:

Categories : Typescript




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.