Menu
  • HOME
  • TAGS

Use translateProvider.useLoader with Typescript

typescript,angular-translate

A silly mistake was not allowing me to retrieve the value of options. The working code is as follows. export class TranslationFilesLoader { public static $inject = ['$http', '$q' ]; constructor( $http: ng.IHttpService , $q: ng.IQService) { return function (options) { var deferred = $q.defer(); var currentLocale = options.key; var...

How to compile TypeScript without using any references whatsoever

javascript,angularjs,typescript,tsd

Running tsc App.ts won't work because a file is being specified. Follow the instructions from the documentation: Using tsconfig.json By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain. By invoking...

Test if an object conforms to an interface in TypeScript

testing,typescript

asserts object conforming to my interface You have to do it manually: expect(typeof object.name).to.eql("string"); // so on Update : Writing code to do the deep assertion for you Since the type information TypeScript sees is removed in the generated JS you don't have access to the type information in...

Why doesn't this code cause a TypeScript type error?

angularjs,typescript,typescript1.5

This is according to spec. Here is your example simplified: interface A{ } interface B { createdId: string; } var foo:ng.IPromise<A>; var bar:ng.IPromise<B>; bar = foo; // No error This assignment is allowed if A is a subtype of B or B is a subtype of A. If this is...

How to implement a parameter decorator in TypeScript?

annotations,typescript,decorator

The return value of this decorator is ignored. This is irrelevant to your situation. The return value of parameter decorators is ignored because they don't need to be able to replace anything (unlike method and class decorators which can replace the descriptor). My problem is that when I try...

Deleting namespace in Socket IO

node.js,namespaces,socket.io,typescript

For anyone else who has this specific problem, I found the answer. I misunderstood the linked question: I didn't realize the array that was being discussed was located in the Server object in SocketIO, not an outside array. Furthermore, at the time of this post, Typescript's SocketIO .d.ts file doesn't...

Pros & Cons of using requirejs (-m amd) for typescript+angular projects

javascript,angularjs,typescript,require,amd

Makes more sense for angularjs? Angular1 : --module amd Angular2 : --module system as that is what the angularjs team uses internally. Is better for large scale angular apps? Yes. --out and reference comments are a bad idea. More : https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md Would be better at minification+obfuscation of large code...

Typescript - is there a way to specify a global reference?

javascript,node.js,typescript

I have to include /// <reference path="lib/node.d.ts" /> in every file No you don't. Just use a tsconfig.json file : https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md ...

Writing an Angular directive with a TypeScript class

javascript,angularjs,typescript,angular-directive

Though it is not quite the same question, this answer included an example of what I'm attempting to do: How can I define my controller using TypeScript? I followed the example in the Plnkr it referenced and found success: http://plnkr.co/edit/3XORgParE2v9d0OVg515?p=preview My final TypeScript directive looks like: module App { 'use...

Import external module ts1.5

typescript

The way Reflect.ts is coded (as a non-exported internal module) means you cannot import members from it directly. You'll have to explicitly use the .d.ts file and import the library purely for its side-effects: /// <reference path="../node_modules/reflect-metadata/reflect-metadata.d.ts" /> import '../node_modules/reflect-metadata/Reflect'; ...

Fill Grid Using Type Script Controller

angularjs,typescript,typescript1.4,typescript1.5

I solved this by using cust in custom.$scope.cust_File as described by @hugues Stefanski. Thanx a lot....

Implement function without name in Typescript

typescript,typescript1.5

You can't do that on classes, but you can do it with a regular function: interface I { (name: string): void; } var C: I = function(name: string) { }; C("test"); // ok C(1); // compile error Then if you change your interface you will be notified by a compile...

How to angularjs app.service and $q in typescript

angularjs,typescript,angular-material

You need to inject helpservice and set it in your constructor argument. static $inject = ['$scope', '$mdSidenav', 'helpService']; constructor(private $scope: any,private $mdSidenav: any, private helpService:any) { } otherwise Typescript does not know what are you referring to as this.helpService, even without TS it will result in an error when you...

Typescript client side socket not connecting with server

node.js,sockets,typescript

Your Javascript (a little bit rewritten): var io = require('socket.io'); var server = io(http); server.on(...); Your Typescript: import io = require('socket.io'); var server: SocketIO.Server = io(); ^^ where is `http`? server.on(...) ...

Mocking Angular $window in unit test cases

javascript,angularjs,unit-testing,typescript,jasmine

You need to use $provide to provide a mocked value in a unit test: beforeEach(() => { module('myApp', ($provide) => { $provide.value('$window', myMockedWindowObject) }); }); You also need to call $rootScope.$apply() to move promises forward in unit tests....

Firebug does not display my JavaScript files

typescript,firebug

Most likely reason: you are using Source Maps. When you use source maps, the browser is able to show the source code that relates to the transpiled JavaScript code. You can switch source maps on and off as it is a compiler setting. tsc --sourceMap app.ts Update I have tested...

How do I access the service provider when registering using typescript class

angularjs,configuration,typescript,service-provider,typescript1.5

Problem is with your registration of provider. Instead of angular.module('apiService').provider('apiService.baseService', BaseServiceProvider); do: angular.module('apiService').provider('BaseService', BaseServiceProvider); and access in the config phase like you do, BaseServiceProvider (postfix word Provider). When injecting the provider instance anywhere else you could just use BaseService. So basically you don't inject with the class name, instead you...

Injecting/Acquiring internal modules in PlatypusTS

angularjs,typescript

How can I inject or acquire the plat.Utils module Have the following in your class: protected static _inject: any = { _utils: plat.Utils }; protected _utils: plat.Utils; ...

Method Put not Allowed in IIS 7.5 using Type Script + Angular Js + Web API Status 405

angularjs,http,typescript,iis-7.5,typescript1.4

It is likely that WebDAV is enabled and is interfering with your request. If you aren't using it, you need to get it out of the way so you can use PUT requests for your Web API. You should be able to do this using your web.config file: <system.webServer> /*...

Create type with two possible variants in Typescript

typescript

TypeScript 1.4 has support for Type Unions, the notation is: var arr: Int16Array|Uint16Array; Common methods that both of these have will be available on arr. If you use instanceof or typeof checks on arr in conditional/branched code, it will infer the type of arr in those branches. TypeScript 1.4. also...

How to generate correct ordering of files with typescript?

typescript

Unfortunately I couldn't get either to work. Is there a solution to this Don't use --out https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md. Instead use external modules: https://www.youtube.com/watch?v=KDrWLMUY0R0...

Use TypeScript lib.core.d.ts instead of lib.d.ts

javascript,node.js,typescript,typescript1.4

Use --noLib compiler option to exclude lib.d.ts and then add reference to lib.core.d.ts in your source files. Equivalent for tsconfig.json would be "noLib": true. If you only need Node.js definitions, you can also use the Definitely Typed one....

TypeScript: workaround for relative reference path?

module,typescript,tsd

I'm wondering if there's a workaround for this Yes. Use a tsconfig.json file : https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md With that you don't need reference comments....

Putting Lambdas in OR statement

typescript

This is how the precedence of the various operators in ECMAScript 6 works. There's a great explanation at http://typescript.codeplex.com/workitem/2360 that walks through each production in sequence....

Getting Error in Angular js + Type Script in http put status 400 using DNN7

angularjs,angularjs-scope,typescript,dotnetnuke-7,typescript1.4

You should get rid of this.$http.put('<%=ResolveUrl("~/API/Search/PutDoSearch")%>', Search) And instead use: this.$http.put("/API/Search/PutDoSearch", Search) ...

d.ts declaration for R.js framework

typescript,typescript1.5

declare module "R" { interface R { (name: string): void; setLocale(locale: string): void; } var RModule: R; export = RModule; } ...

How to type JSON results

typescript

The issue is that dataService.getSection('HOME_PAGE') is being inferred to return Promise<void> and therefore data is of type void. Fix in your dataService: getSection(secName: string): Promise<any> Or something stronger if you don't want any. (Some basic docs on annotations : http://basarat.gitbooks.io/typescript/content/docs/types/type-system.html) ...

TypeScript 1.5 doesn't produce output

typescript

This behavior changed in 1.4 if you are compiling from Visual Studio. To change to the old behaviour open the csproj/jsproj in for example notepad and add the following to it <PropertyGroup> <TypeScriptNoEmitOnError>false</TypeScriptNoEmitOnError> </PropertyGroup> It had something to do with the incremental build system where you had for example 5...

View is not a constructor for Backbone under Typescript

javascript,backbone.js,typescript

Backbone is undefined. How would I import it? Using a script tag. Or an external module loader like requirejs along with AMD modules (--module amd). More : https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1...

How to pass optional parameters in TypeScript while omitting some other optional parameters?

typescript

You can just pass in undefined: export interface INotificationService { error(message: string, title?: string, autoHideAfter? : number); } class X { error(message: string, title?: string, autoHideAfter?: number) { console.log(message, title, autoHideAfter); } } new X().error("hi there", undefined, 1000); Playground link....

What is the type of an object literal key as defined in TypeScript?

javascript,enums,typescript,webstorm,object-literal

The code for keyMirror assigns the property key to the value: for (key in obj) { if (obj.hasOwnProperty(key)) { ret[key] = key; } } Therefore, the type of returnVal and CrudTypes.CREATE should be string. Note that Object.keys(...) returns string[] in TypeScript and that the following code outputs string for all...

Why Chrome shows \ufeff symbol and gray lines in TypeScript?

javascript,visual-studio,google-chrome,typescript,google-chrome-devtools

It seems that Chrome somehow doesn't like UTF-8 with BOM. And this is exactly an encoding which my instance of Visual Studio did save file in. I have switched the encoding to UTF-8 without BOM and the described problems have disappeared. How to: corresponding StackOverflow question. In two words: 1)...

Uncaught ReferenceError: angular is not defined using type script

angularjs,angularjs-scope,typescript,typescript1.4,typescript1.5

I have solved this Question by changing the sequence of my java script references. as :- 1.jquery-latest.js 2.app.module.js" 3.Controller.js" 4.Interface.js" 5.angular.js" 6.angular.min.js" 7.app.routes.js" ...

How are the definitions files loaded in typescript

typescript

These days everyone use tsconfig.json, either original or atom-flavored (in Atom editor). When using tsconfig.json, you can omit files list and typescript compiler will compile all *.ts files it will find in any subdirectory, including *.d.ts. Excluding files via exclude is on the way, as well as files globbing. If...

How to expose TypeScript modules in NodeJS?

javascript,node.js,typescript

I'd like to include this library in both TypeScript and JavaScript Node projects. What is the general strategy to do this? Compile with the following to get the js output: --module commonjs --outDir ./dist This should make your project consumable by JS projects. To make it consumable by TS...

How to implement custom sort for koGrid?

javascript,sorting,knockout.js,typescript,kogrid

Just try to modify your code like this View : <div data-bind="koGrid: gridOptions"></div> viewModel: vm = function () { var self = this; self.myData = ko.observable([{ hours: '113.02 hours' }, { hours: '13.01 hours' }, { hours: '303.01 hours' }, { hours: '33.01 hours' }]); self.gridOptions = { data: self.myData,...

Auto-Build TypeScript Project in Visual Studios Code 2015

visual-studio,visual-studio-2013,typescript

I'm not sure whether you use Visual Studio Code or Visual Studio 2013. I assume it's VS Code (if it's not, consider switching. VS Code is really good!). Now I'll quote myself from another answer. You can do this with Build commands: Create a simple tsconfig.json with watch = true...

Angular 2/Typescript: require not found

typescript,gulp,angular2

I was not able to get that working but was able to get it working with gulp-traceur. Here is my gulpfile. var gulp = require('gulp'); var gulpTraceur = require('gulp-traceur'); var through2 = require('through2'); var gutil = require('gulp-util'); var sourcemaps = require('gulp-sourcemaps'); var copy = require('gulp-copy'); gulp.task('compile',function() { return gulp.src("./*.es6.js") .pipe(sourcemaps.init())...

How do I make an Angular service using typescript?

angularjs,typescript

The service should look like the following. Don't forget registering the service in the module: export class MDCurrencyService implements IMDCurrencyService { constructor(private $http: ng.IHttpService, private $q : ng.IQService) { } get(): ng.IPromise<MDCurrency[]> { var deferred = this.$q.defer(); this.$httpService.get('/Master/CurrencyGetAll').then(response => { deferred.resolve(response.data); }).catch( reason => { deferred.reject(reason); }); return deferred.promise; }...

Typescript file exporting interfaces comes up 404 using JSPM

typescript,typescript1.5,jspm,systemjs

from 'customer/ICustomer' For typescript you need to use the complete relative path e.g. ./customer/ICustomer. There is discussion to remove this limitation : https://github.com/Microsoft/TypeScript/issues/2338...

How to stop visual studio generate typescript js and js.map files while publishing

visual-studio-2013,configuration,typescript,publishing

However while publishing my project, it still generates js and js.map file foreach .ts files. You probably have different config for debug and release. Make them the same....

C# Rest API returns string with double quotes

angularjs,rest,typescript,umbraco7

I found another way than @basarat is suggesting, from the comment form @ArghyaC. The problem is that Umbraco's REST controller builds on asp.net's ControllerApi, and defaults to xml. The apostrophes comes from the xml serialize. The solution is simple force json as the return value instead. I don't dare to...

How to pass an arugment to a typescript module?

typescript

Export the variable you want to modify: module validator { export var regex = /^[A-Za-z]+$/; // <-- export var export var ok = (s: string) => regex.test(s); }; validator.regex = /.*$/; This will make module behave similar to a static class: you have a single point of access to this...

Node.d.ts issues errors using typescript compiler, how do I fix?

node.js,visual-studio,typescript,jasmine,protractor

Typescript wants a semicolon after You are using an older version of TypeScript. Upgrade to TypeScript 1.4 or later....

Mismatched anonymous define() in Chrome extension content script

google-chrome-extension,requirejs,typescript

The docs for the error message state: Be sure to load all scripts that call define() via the RequireJS API. Do not manually code script tags in HTML to load scripts that have define() calls in them. As described in this question, it seems that if you use import in...

Namespace keyword in TypeScript

c#,namespaces,typescript,keyword

You can read about it in the namespace keyword issue, but the basic idea is to differentiate between internal (namespace) and external (module) modules. To better align with ES6 modules as suggested in #2159, this PR introduces a new namespace keyword as the preferred way to declare what was formerly...

When Using Typescript+angularjs the api result is not displaying in html

angularjs,typescript

You have to be careful with this semantics. In this code: return this.$http.get('facilities.json').success(function(response) { this.result = response; console.log(this.result); }) this is not referring to your test instance, but instead to whatever context the function is running in. Instead do this: return this.$http.get('facilities.json').success((response) => { this.result = response; console.log(this.result); }) Now...

Inject dependency to the angularjs directive using typescript

angularjs,angularjs-directive,typescript

Try this way: class SetFocus implements ng.IDirective { //Directive settings restrict :string = 'EA'; scope : any= {}; //Take timeout argument in the constructor constructor(private $timeout: ng.ITimeoutService) { } link: ng.IDirectiveLinkFn = ($scope: ng.IScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes) => { //refer to the timeout this.$timeout(function() { $element[0].focus(); }, 0); }...

Extending an interface from a third party definition file

typescript,sequelize.js

Fix at : interface DataTypeString extends DataTypeStringBase { (length?:number): any; // ADD this } A PR + TEST would be appreciated :) Update Would it be possible somehow to implement this in my own .d.ts file, extending the provided one? FAILED ATTEMPT Untested but probably correct: declare module "sequelize" {...

Angular directive dependency injection - TypeScript

angularjs,typescript

Just specify $timeout as the factory constructor function argument and pass it through. static factory(): ng.IDirectiveFactory { var directive: ng.IDirectiveFactory = ($timeout:ng.ITimeoutService) => new myDirective($timeout); directive.$inject = ["$timeout"]; return directive; } ...

Visual Studio 2015 RC + RequireJS + jQuery

jquery,requirejs,typescript,visual-studio-cordova

I'm not sure if this is a problem with RequireJS and jQuery or VS2015RC + Cordova. The error is that jquery isn't resolving to the jquery.js file (an HTTP 404 error). Check the HTTP Get request made by the browser. It will be something like http://yourapp/scripts/lib/jquery.js. Make this GET...

TypeScript export imported interface

typescript

There is an export import syntax for legacy modules, and a standard export format for modern ES6 modules: // export the default export of a legacy (`export =`) module export import MessageBase = require('./message-base'); // export the default export of a modern (`export default`) module export { default as MessageBase...

Update Knockout Observable string in refresh function

javascript,knockout.js,typescript

This works fine for me as the entire app. I can't tell what I'm doing differently from what you describe, so I'm just including the whole thing. class TodayVM { asOfString: KnockoutObservable<string>; constructor() { this.asOfString = ko.observable(''); this.updateSummary(); } updateSummary = () => { this.asOfString(new Date().toDateString() + " " +...

Looping through an enum, TypeScript and JQuery

jquery,enums,typescript,ienumerable,enumeration

TypeScript enums when compiled into plain JS contain both the symbolic name AND the numeric values as properties and that explains why you get FrontEnd, BackEnd, Designer, 0, 1, 2 when you try to enumerate the properties of the object. As best I know, there is no post-compile way to...

Typescript 1.5 - 'Duplicate identifier' errors

typescript,typescript1.5

The problem is in typings/webaudioapi/waa.d.ts. TypeScript 1.5 includes Web Audio API declarations internally and you get duplicate identifiers. To solve the problem, remove the typings/webaudioapi/waa.d.ts file and remove the reference to it from typings/tsd.d.ts In previous versions of TypeScript compiler this file was not included and errors didn't show up....

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

javascript,typescript,typescript1.5

It looks like you're using wrong dash character in your tsc --out. TypeScript compiler looks at your command and instead of "invoke tsc with file Test.ts and output to sample.js" sees something along the lines of "invoke tsc with 3 files: --out, sample.js, Test.ts". It then looks for these files...

How to declare knockout component in typescript?

javascript,knockout.js,typescript

Try to use this approach: // import knockout import ko = require("knockout"); // your viewmodel class class TodayViewModel { todayText = ko.observable<string>(); } // register the component ko.components.register("like-widget", { viewModel: TodayViewModel, template: "<span data-bind='text: todayText'></span>" }); P.S. you will need knockout.TypeScript.DefinitelyTyped...

AngularJS how to use $q in Typescript

javascript,angularjs,typescript,q

There are several ways to return a promise... $http returns a promise with each of its ajax calls, $timeout also returns a promise. That being said you want to return a promise based upon something other than a scheduled event ($timeout, $interval) via $q you can do this... // assume...

How can this be undefined in the constructor of an Angular config class?

angularjs,constructor,typescript,undefined,this

Config functions aren't classes and shouldn't be written as such. Angular is invoking them without new and thus this will be undefined (or, God help you, window in non-strict mode). It doesn't really make sense to use a class here as there's no instance to be kept around. If you...

TypeScript does not detect union type with an && operator

typescript

Is this a bug or am I missing something This is by design. According to spec the inferred type from && is the type of the last expression. So the inferred type of the following is string: var x = false && "foo"; This to support a common JavaScript...

8K command line restriction when publish typescript from VisualStudio

typescript,tsc

You can pass the the command line arguments as a file e.g. tsc @sometFileThatContainsTheArguments.txt. That overcomes any command line limits PS: This is a trick that grunt-ts uses as well btw...

Typescript union type not working

types,typescript,typescript1.4

You will need to do some type checking and casting to handle this scenario: (member: resources.IMember) => { return member.user.id == user.id; if (typeof (member.user) === 'number') { return member.user == user.id; } else { return (<ISimpleUser>member.user).id == user.id; } }).length > 0; Just because you know the possible types...

What is the use case for supporting “both types of index” (numeric and string) in TypeScript?

javascript,typescript

I'd be glad to have some code examples demonstrates what they meant. The following is allowed : interface A{ } interface B{ foo: number; } interface Something { [index: string]: A; [index: number]: B; } But this is not: interface A{ foo: number; } interface B{ } interface Something...

How to format the values of a model in Marionette Backbone View before rendering?

view,formatting,typescript,rendering,marionette

By checking this link: http://derickbailey.github.io/backbone.marionette/docs/backbone.marionette.html You will find that serializeData is being used just before rendering the template So by overriding it, like below you can format the object values any way you want before rendering serializeData():any { var obj = super.serializeData(); obj.totalEnergy = Math.round(obj.totalEnergy).toFixed(0) return obj } ...

How to Add AngularJS 1.4 in Visual Studio 2015 RC Cordova TypeScript Project

angularjs,cordova,typescript,visual-studio-2015,visual-studio-cordova

Could someone share me the steps about how to add AngularJS in the TypeScript Cordova project of VS2015RC? Add angular.js Get definitions for angular : https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular.d.ts Start using TypeScript .ts files like any other angular project e.g. https://github.com/tastejs/todomvc/tree/gh-pages/examples/typescript-angular ...

Cross Domain Request with TypeScript and Angular $http Service

javascript,angularjs,typescript

I don't believe that it is possible to do this, which may seem like bad news. But I have good news. You don't need to do this, because setting useXDomain to true has no effect. In fact, useXDomain is not even really a thing in Angular. Here is a great...

Setting dynamic properties with key from a private collection in TypeScript

typescript

The primitive type of a string is string and not String. Change the interface accordingly: interface TestObj { name: string; } String is for the String object while string is for the primitive type. For example: var obj: any = {}; var strObj = new String("test"); // typed as String...

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

angularjs,typescript,angular2,typescript1.5

Your issue is that the documentation is not in sync. If you followed the documentation for installation recently then it would have installed the typings for latest version alpha26, which has a lot of broken changes. And the documentation uses a23 version with that version of code. You can either...

`this` in callback points to wrong object

typescript

Since you are passing the function to someone else to call in .then(this.activateView); you need to preserve the context yourself, best if you do : .then((view)=>this.activateView(view)); More about this : https://www.youtube.com/watch?v=tvocUcbCupA...

“Variable 'X' can be made constant”, what does 'constant' mean?

typescript,resharper,ecmascript-6

It's nothing complicated. It's always better to use const over let (and definitely var), since const makes it a bit easier for other coders, or you when you come back to the same code in the future, to understand what is going on, since you only have to look at...

How to update the view after changing the model in Angular2

javascript,typescript,angular2

I found the issue. Apparently, its a bug to be fixed in alpha 27. See this bug report: https://github.com/angular/angular/issues/1913 Angular2 uses zonejs to know when to start the digest cycle (the dirty checking and update the view). As of now, zonejs is not triggered after fetching data with the new...

Using Angular 2 with older browsers thanks to TypeScript?

javascript,internet-explorer-8,internet-explorer-7,typescript,angular2

Angular 2 will only support modern browsers: Modern browsers means the set of browsers known as ‘evergreen’ or always automatically updated to the latest version. Building for these browsers let us drop many hacks and workarounds that make AngularJS harder to use and develop on than it needs to be....

Center of chart(pieChart)

javascript,css,charts,highcharts,typescript

Pie center can be calculated using pie series center array (x and y coordinates), plotLeft and plotTop. Using renderer.text it is possible to add text. In redraw event additionally rendered text should be adjusted to stay in the center of pie. Example: http://jsfiddle.net/1917s4pL/ $(function () { var chart = new...

TypeScript project organization, compile into a single JS file?

javascript,oop,typescript

Yes, you want to use gulp or grunt. I suggest gulp, but that's a personal preference. You can use this to inject your scripts in a particular order based on your file naming convention.

How to detect overflow HTML elements

javascript,jquery,html,css,typescript

Compare scrollWidth/scrollHeight with clientWidth/clientHeight of the element. if (e.scrollWidth > e.clientWidth){/*overflow*/} https://jsfiddle.net/pdrk50a6/ Edit: I do not know your root element, yet in the end it is going to be something like this. document.body.onresize = function(){ var tR = []; var tL = document.querySelectorAll('div'); for(var i=0, j=tL.length; i<j; i++) if (tL[i].scrollWidth...

Typescript definition for existing jQuery plugin with nested function

typescript

You can use an anonymous interface (or whatever it is officially called) to define a function and its static fields together: interface JQuery { foo: { (options: any): JQuery; bar: <T>(input: T) => T } } Playground See also: Implementing TypeScript interface with bare function signature plus other fields...

Sublime 3 JS Snippets to Typescript

javascript,typescript,sublimetext3,code-snippets

You have to add a typescript source to your snippets scope. <scope>source.js, source.ts</scope> There is a exemple of snippet that you can find in the TypeScript package: <snippet> <content><![CDATA[ class ${2:ClassName}${3: extends ${4:AnotherClass}} { $5 ${6:constructor}(${7:argument}) { ${0:// code...} } } ]]></content> <tabTrigger>class</tabTrigger> <scope>source.ts</scope> <description>class …</description> </snippet> ...

Typescript js.map files loaded by the browser using a wrong path

javascript,typescript

My best guess is that you need to change the sourceRoot config attribute to point to the correct path ;). Something like: {"version":3,"file":"Spinner.js","sourceRoot":"/scripts/", ... should do it. ...

How to do dynamic objects in TypeScript

typescript

Yes, that kind of behavior can be achieved, but in slightly different way. You just need to use typescript interface, like: interface IValue { prop: string } interface MyType { [name: string]: IValue; } that will be used for example like: var t: MyType = {}; t['field1'] = { prop:...

tsc --out weird behavior when using 'import' in my files

typescript,tsc

Settings "out":"public/all.js" and "module":"commonjs" are mutually exclusive. You should either: Use internal modules and let the compiler concatenate output file for you (remove module setting from config); @basarat would advise you against it, but I think it's not that bad, especially for small projects. Use external modules and concatenate output...

is it possible to use TypeScript and Babel together

javascript,typescript,babeljs

I'd like get the best of both world by using TypeScript to organize my code then use babels ES6 features like asyc/await and others. Is this possible. Not out of the box. I would recommend against it unless you are willing to start compiler hacking yourself. Reason is that...

Trying to implement an object-oriented design model for a simple navbar using TypeScript

javascript,jquery,typescript

this is of the wrong type (window) and not the instance of the class. The best way to fix It is by using an Arrow function to capture the this reference like below: private clickListener(target: JQuery): void { (target).on("click touchend", () => { if (!(target === (this.body))) { event.preventDefault(); event.stopPropagation();...

Angularjs+Typescript directive implementing $compile

angularjs,angularjs-directive,typescript

So I found a way to get it to work but it is not as elegant as I would have liked. angular.module('formDirectives', [], function($compileProvider){ $compileProvider.directive('catElement', ($compile) => { return new Element($compile); }); }) ...

ng-switch in Angular2

typescript,angular2,ng-switch

You need to import NgSwitchWhen and NgSwitchDefault, add these to the import statements

What is the correct tasks.json config for compiling typescript in Visual Studio Code?

typescript,vscode

I had the same problem. It was a wrong PATH variable to the TypeScript compiler. (try to type "tsc -v" in a command window). The tsconfig.json is supported in TypeScript version 1.5. My PATH variable was set to version 1. When I changed the system PATH variable to the updated...

Using TypeScript type definitions with Webstorm 10 [duplicate]

node.js,typescript,webstorm

Using that dialog, I downloaded the node and express type definitions and can see them in the External Libraries section of my project. However, I still get the same error about "require" That dialog gets TypeScript definitions to use with JavaScript. You need to download the typescript definitions manually...

JavaScript map(), undefined property of object from the collection

javascript,typescript

The most likely answer is that val is a string containing the JSON you see in the console. If it were an object, the console output would look different. It looks like you need to put a JSON.parse in there. You haven't shown the original TypeScript, but in the JavaScript...

Compiling TypeScript with filter() thisArg

javascript,node.js,typescript

This error arises from the fact that you have created a class-level method filterObjects() and use it in another context. TypeScript compiler doesn't know about the intended use of this method, it decides that you're going to use it in the Sample context: sample.filterObjects(). You have at least 2 different...

All TypeScript to Single js File - How to tell page which module to execute

asp.net,visual-studio,visual-studio-2013,typescript

The problem I ran into, as you'd expect, is that the entire .js file is executed, and not just the module(s) that I need my page to execute. You shouldn't have code randomly put at a global level. The global level of your code be just functions and class...

RequireJS and TypeScript Class - Cannot call function externally

javascript,requirejs,typescript

IMO classes in TypeScript should be used only if you need multiple instances with data associated to each instance. A Helper is usually just a bunch of static methods. Therefore I suggest to use a module instead (untested): Shared/ModalHelper.ts module ModalHelper { export function saySomething(something: String) { alert(something); } }...

How to load System.js modules with TypeScript?

javascript,typescript,aurelia,systemjs

You may want to use d.ts definition files for registration with TypeScript Definitely Typed registry for use with tsd package manager. You can find different implementations on github, for example here or here. Also this tutorial might be useful.

how to do something when data from service is ready in angular?

angularjs,typescript

mdCurrencyService.get() should be implemented as an asynchronous service returning a promise. It can be utilized this way: mdCurrencyService.get().then(function (currencies) { // process result here $scope.currencies = currencies; }); ...

Exception with type definition for random-string module

node.js,module,typescript

Your declaration says there is a module named random-string with a function named randomString within it... So your usage should be: console.log(randomString.randomString({ length: 10 })); console.log(randomString.randomString()); If the module does actually supply the function directly, you should adjust your definition to do the same: declare module "random-string" { function randomString(opts?:...

TypeScript + JavaScript: Is not a function at x?

javascript,angularjs,typescript

The reason is because action function being a part of the object (literal) is not an instance of the actual class that implements the reference to its action property, search @ private actionItems:IActionItem[] = [{ name: 'Search', icon: 'magnifier', action: this.search, //<-- this one className: 'visible', order: 2 } ];...

TypeScript: Lambdas and using 'this'

lambda,typescript,this

TypeScript's handling of this in arrow functions is in line with ES6 (Read: Arrow Functions). Due to that specification, it would be inconsistent for it to act any other way. If you want to access this of the current function, then you can use a regular function. For example, change:...

Angular with Typescript: HTTP Injector Factory vs. Service

angularjs,typescript,angular-http-interceptors

Notice the "request" vs. "Response". The former will be called. The latter will not. JavaScript is case sensitive. Response is not the same as response. You need to keep it lowercase. When the functions are correctly called, the "this" object refers to the global window and not the object....

Cannot find external module 'angular2/angular2' - Angular2 w/ Typescript

angularjs,typescript,angular2

Adding these files to the head will give you the latest working version of Angular2. <script src="https://github.jspm.io/jmcriffey/[email protected]/traceur-runtime.js"></script> <script src="https://jspm.io/[email protected]"></script> <script src="https://code.angularjs.org/2.0.0-alpha.26/angular2.dev.js"></script> Source: Angular.io: 5 Minute Quickstart...