Duplicate Identifier in WinJs.d.ts - javascript

I am trying to use TypeScript in a Windows 8 app (html5/JS)
I have looked at the sample app
The app uses a typing definition file for WinJS (WinJS.d.ts).
I need to edit this file as it is not complete. However the file has an interface extension for the Type Element adding a property for winControl(typed to any).
This line gets and error of "Duplicate identifier 'winControl'" I am unable to locate and other place this is.
Also, there are locations in my code that i get errors as there is no property named winControl

To solve this problem you must
remove lib.d.ts from anywhere in your project path (or the path to your winrt.d.ts) folder. It is conflicting with the definitions in your local typescript install folder
make sure that you do not have any of your ts (and JS files) identified as content as they will be copied to your deployment directory and will cause the same duplicate issue (there will be two definitions of everything).
I would suggest opening the output window before you do a build. It will let you see what is causing issues since tcs is being run as a command line behind the scenes for you

Sounds like the same issue that I've experienced when trying to augment the Window interface, a bug that is currently being working on:
http://typescript.codeplex.com/workitem/176
However he only mentions lib.d.ts, you may want to add your problems to the issue to either make sure that it's also being fixed, or to rule out that this is what causes your problem.

Related

Getting 'cannot redeclare block-scoped variable' for 'message' variable

I'm an desktop application developer trying to learn the avalanche of technologies for web programming. I decided to focus with Angular(2-4 whatever) because it seemed like the it might be around for more than a year. I'm taking a course that is focusing on TypeScript right now. I'm using Visual Studio Code (1.14.0 - I just updated it) with TypeScript version 2.4.1 (That's what it shows in the lower right corner).
The instructor is showing us how to 'transpile' with command lines (which was another mess I wasted my morning on - see tsc.cmd as opposed to tsc).
The example in question is simply this one line, the first and only line in the Visual Studio Code editor:
let message = 0;
I get the red line of error under the 'message' telling me that:
[ts] Cannot redeclare block-scoped variable 'message'.
It worked for the instructor (on his MAC) but so did the ts compiler command.
If I change it to
let messag = 0;
The error goes away. I can't find where message is a command, statement or global variable in Type Script.
It seems like I'm running the latest of node and type script. I just worry that something is not correctly installed on my machine.
I am still getting use to the idiosyncrasies of VS Code.
My issue was that I put 'archive' copies of my previous code in a subfolder not realizing that these would be loaded as part of the 'assembly'.
Don't simply close the folder! If you are looking at just a single file, the editor will turn off intellisense for typescript.
My solution was to move my archived files out from under the folder AND rename them so their extension was no longer .ts.
Is it a npm project? If not - make it one and use the features of tsconfig.json, where you can exclude files if necessary. Maybe also use GIT? You could create a template repo (with a default configuration) for cloning and then adding specific stuff.

Is there a root keyword in JavaScript or why does Sublime display it like this?

I used a variable called root in a recent JavaScript project, and Sublime Text 3 displayed it like this:
So I'm wondering if there is a root keyword in JavaScript, and if so what does it do... Otherwise I'd like to know a way to stop Sublime Text from displaying it differently... The console, however, says ReferenceError: root is not defined when I type it in there.
root used to be a variable in Node.js however it was deprecated in v6.
UPDATE:
The old URL doesn't work anymore, so I've updated it with the Internet Archive's Wayback Machine's version of it, also here's the merge request with the change.
The declaration comes from this file in Sublime.
UPDATE:
To remove the syntax rule, install PackageResourceViewer as per the instructions here and then open up the JavaScript.sublime-syntax file, find the word root (there's currently only one) and remove it (and the following | character).
Note that you'll need to run Sublime as an administrator on Windows in order to edit the file.
It seems root is not a keyword of javascript:
https://www.w3schools.com/js/js_reserved.asp

Calling a function defined outside of the Javascript library

I am working on video.js library. I was trying to modify it, so that it uses a custom player instead of the HTML5 player.
So I replaced the function calls to play() etc with the calls to my custom player(say custFunc1()). These calls are defined in a separate javascript file: custPlayer.js.
So in my index.html file, I will first include the custPlayer.js file and then the built video.js file.
However the problem is that while building the video.js package using grunt, I get the error that custFunc1 is not defined and thus grunt is not able to create the video.js library.
Now I was able to find out from a colleague that adding
/* global custFunc1 */
at the beginning of the particular file in the video.js package from where I was calling custFunc1 resolves the issue. The grunt build succeeds and it works fine.
So what I want to know is:
How does this actually resolve the issue, since this is exactly like a comment in javascript, how does it treat this differently and understand that it indicating that the function definition will be present outside the library?
Is the word global some sort of keyword in javascript?
Are there other ways of achieving this apart from what I mentioned?
On a slightly different note, I wanted to ask if grunt is the rough equivalent of make ?
Your javascript is being linted as part of your grunt process, if you look at the root of your project folder you should see a file like .jshintrc or something along those lines (different depending on the linter).
Your current settings means that the linter is going through your .js files one at a time and if it comes across a variable or function from another files it's throwing the error your seeing. You can either turn off this check or add custFunc1 to an array of known global variables. In jshint you do it like so - https://github.com/gruntjs/grunt-contrib-jshint#jshintrc
{
"globals": {
"custFunc1": true
}
}
The globals will probably already be present in the file, so just add custFunc1: true to it.
Oh and to answer question 1 - the comment type syntax tells the linter to ignore it's settings for that current file, basically overriding the settings in the .jshintrc file.
2 - Yes it's a setting in jshintrc and your adding custFunc1 to it inside the file itself instead of globally in the .jshintrc file.
3 - Mentioned above.
4 - Never used maker but yes i believe its similar in that its a pre process tool

After Effects applyPreset : bad path

So I'm totally new to ExtendScript, and already amazed. I've been trying to automatize the creation of standard videos, and to do so I want to create presets and apply them to footage. So I use the applyPreset(File) method of the layers.
The new File("path") seems to open fine, but then applyPreset is unhappy because it tells me my path is wrong. Namely, After Effects says "Unable to call applyPreset because of parameter 1 : incorrect path "/Users/Charles/Documents/Slide-In-1.ffx"". Yet my path, I can assure you, is absolutely correct. Being on Mac, I used "~/Documents/Slide-In-1.ffx", which got replaced by "/Users/Charles/Documents/Slide-In-1.ffx" according to the error output (this replacement is correct, clearly). So where's the problem ? How can I check that a file has indeed been found and opened by JavaScript ? Thanks a lot in advance.
Charles
Seems my path was in fact bad. Something fishy, but I had to change my file organisation anyway to have a clean centralized git repo, and it started working.
you can test if a file exists like this:
if( File(YOURPATH).exists )
If true, this object refers to a file or file-system alias that actually exists in the file system.
http://jongware.mit.edu/Js/pc_File.html

jQuery Intellisense: Common reference file (stdafx) for vsdoc

I moved the jQuery in my project over to Microsoft's CDN yesterday so finally have jQuery intellisense back. Yay! However, I apparently need to include the following in all my .js files:
//These references should enable intellisense within this file
///<reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.js" />
///<reference path="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/jquery-ui.min.js" />
I would prefer to have a single js file which contains the above references such that I have a single, unchanging reference in all my js files like so:
//These references should enable intellisense within this file
///<reference path="/shared/js/stdafx.js" />
The idea is that stdafx.js would be the file containing the jQuery references. Then I have only one place to update the versions or add additional references. I gave it a quick go, but it didn't seem to work. Can anyone figure out a way to make this happen?
Actually the above common reference did work in the end. I didn't realize how quirky VS was in regards to js intellisense. Funny enough it kicked in after compiling the project.
I did try Ctrl-Shift-J which refreshes the JavaScript as well. It takes a few seconds for it to kick in so give it a chance. Another tip I read was dragging the common.js file into the editor of the .js file I wanted to add the common reference to. This sanity check ensured I had the correct path (it did). It added a relative path (../shared/stdafx.js) but I was able to use an absolute path (/shared/js/stdafx.js) which means I can modify the VS .js template for new js files.
So I would suggest anyone who comes across this question to persevere, refresh the JavaScript, compile, even close and reopen VS as it will hopefully kick in for you eventually.
For anyone still wanting jQuery intellisense in their .js files (and why wouldn't you) you need to 'reference' the correct jQuery VSDOC file, that MS created for Visual Studio intellisense:
///<reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2-vsdoc.js" />
To test it, type:
$(
You should see full intellisense with PARAMETERS, as well as members. If you only see a single list of members, it's not working.

Categories

Resources