Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS 2013 save and compile output vs build compile output #1812

Closed
craigktreasure opened this issue Jan 26, 2015 · 58 comments
Closed

VS 2013 save and compile output vs build compile output #1812

craigktreasure opened this issue Jan 26, 2015 · 58 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@craigktreasure
Copy link
Member

I have an enum in an interface that, when used in my TS code in TypeScript 1.3, was output as a constant. This is no longer the case in 1.4 after saving my file. When i build the project, the enum code is properly output as a constant. Using VS 2013 update 4 with TypeScript 1.4 installed.

Enum declaration file (Colors.d.ts):

declare module server {
    enum Colors {
        Red = 0,
        Green = 0,
        Blue = 0
    }
}

TS Code:

if(box.color === server.Colors.Red) {
...
}

JS Output after save:

if(box.color === server.Colors.Red) {
...
}

JS Output after build (correct, or what i consider to be correct since there is no implementation of the enum):

if(box.color === 0 /* Red */) {
...
}

The same is observed if the enum is declared using the new "const enum" feature.

@mhegazy mhegazy added the Bug A bug in TypeScript label Jan 26, 2015
@mhegazy mhegazy added this to the TypeScript 1.5 milestone Jan 26, 2015
@vladima
Copy link
Contributor

vladima commented Jan 26, 2015

Can you try the latest bits from master? It seems that root cause of this issue is the same with #1742 that was recently fixed

@craigktreasure
Copy link
Member Author

What and where do I need to replace?

Sent from my Windows Phone


From: Vladimir Matveevmailto:notifications@github.com
Sent: ‎1/‎26/‎2015 3:06 PM
To: Microsoft/TypeScriptmailto:TypeScript@noreply.github.com
Cc: Craig Treasuremailto:craigktreasure@outlook.com
Subject: Re: [TypeScript] VS 2013 save and compile output vs build compile output (#1812)

Can you try the latest bits from master? It seems that root cause of this issue is the same with #1742 that was recently fixed


Reply to this email directly or view it on GitHub:
#1812 (comment)

@vladima
Copy link
Contributor

vladima commented Jan 27, 2015

  • run 'jake clean local' to build the TypeScript compiler\language service bits - build result will be dropped to 'build\local' folder
  • go to <ProgramFiles>\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript
  • backup existing 'typescriptServices.js' somewhere and replace it with one that was build on the step 1

@basarat
Copy link
Contributor

basarat commented Jan 27, 2015

I've been getting this in 1.4 as well. Didn't investigate myself since I wasn't bothered but I've done many a commits like : TypeStrong/atom-typescript@ed04b58#diff-fe4e718ca060808778e53a950eb4764aL7 then again I had grunt, visual studio, and atom / ts language service fighting to build the same files :)

@craigktreasure
Copy link
Member Author

@vladima A new copy of typescriptServices.js seems to have fixed the issue when i mark the enum declaration in the d.ts file as a const enum, but not for the scenario in which the enum is not a const enum.

@Stompf
Copy link

Stompf commented Jan 27, 2015

I've tried the new copy of typescriptServices.js and for me the problem still exists. It seems to work about 50% of the time when saving but in the other 50% it still compiles to the enum string (ex. server.Colors.Red in craigs example)

@craigktreasure
Copy link
Member Author

In my case, I want it to compile to a constant since it is declared in a declaration file and they're isn't an implementation of the enum.

Sent from my Windows Phone


From: Stompfmailto:notifications@github.com
Sent: ‎1/‎27/‎2015 4:20 AM
To: Microsoft/TypeScriptmailto:TypeScript@noreply.github.com
Cc: Craig Treasuremailto:craigktreasure@outlook.com
Subject: Re: [TypeScript] VS 2013 save and compile output vs build compile output (#1812)

I've tried the new copy of typescriptServices.js and for me the problem still exists. It seems to work about 50% of the time when saving but in the other 50% it still compiles to a constant


Reply to this email directly or view it on GitHub:
#1812 (comment)

@Stompf
Copy link

Stompf commented Jan 27, 2015

Yea I mixed up the words :) What I mean is that the output still sometimes is wrong like "server.Colors.Red" instead of "0 /* Red */" in your example for me when I save in VS 2013 even with updated typescriptServices.js. Tried edited my previous comment to reflect that

@vladima
Copy link
Contributor

vladima commented Jan 30, 2015

Can you write a short video with repro using Screen2Gif or similar tool? If you can please also capture the structure of the virtual project in Solution Navigator and set of files at the top of the screen

@Stompf
Copy link

Stompf commented Jan 30, 2015

Hello! I tried building the latest master again and now it works, I think I did something wrong the first time (sorry first time building from master). So you can disregard me.

@vladima
Copy link
Contributor

vladima commented Jan 30, 2015

@craigktreasure can you please provide a video with repro that will involve non const enums?

@craigktreasure
Copy link
Member Author

@vladima I'll send a sample project your way later today.

@mrcrowl
Copy link

mrcrowl commented Feb 3, 2015

This looks the same as the issue I'm having in #1916.

Example project: https://www.dropbox.com/s/xc34f0q6rhc0amm/ExampleProject.zip?dl=0

@craigktreasure
Copy link
Member Author

@vladima I believe this is fixed now.

@vytautas-pranskunas-
Copy link

I have replaced typescriptServices.js file and now on save it does not generate any file and console sys: "Input file contained syntax errors. Output generation skipped."

I do not have any errors and on build everything works fine.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 24, 2015

Can you share a sample file where you are wrong this?

@vytautas-pranskunas-
Copy link

I dont know whic file exactly because after i pased same code to clean project it compile. However build passes with no errors. Console does not show anything on save except that error.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 24, 2015

The issue would probably be linked to the contents of your project, it would help a lot if you can detect the code pattern that consistently triggers the issue.

@vytautas-pranskunas-
Copy link

Hello again,

I have found problem.
I reference

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

in my proj file and props file contains this line:

<TypeScriptNoEmitOnError>true</TypeScriptNoEmitOnError>

if I remove it everything compiles fine.

p.s. off topic: mshould i update ToolsVersion="4.0" in same file because of typescriptservices.js file changed?

p.p.s. one more offtopic question which i cannot find clear answer on the web - shuold i use delegate or method syntax in classes. In ecma6 there is methods syntax but delgates generates better javascript and prevents overriding. so:

class Boo {
boo(){} 
or 
boo = () => {}
}

@DanielRosenwasser
Copy link
Member

Use method syntax, since it will be initialized once on the prototype. The property initializer will be set in the constructor body and a new closure may be created once per instantiation.

@vytautas-pranskunas-
Copy link

Ok. What about my main problem about compilation problem of typescript with props set?

@vytautas-pranskunas-
Copy link

There is nothing to share actually. Have you tried to add line I pasted before? Because as I mentioned before it stops to compile when this import is in .proj file

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

because of this line in that import

<TypeScriptNoEmitOnError>true</TypeScriptNoEmitOnError>

if you add to empty web project you should be able to reproduce it.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 30, 2015

@vytautas-pranskunas- what kind of web project are you using. i am still not able to repro this issue with the different projects i tried.
compileonsave

@vytautas-pranskunas-
Copy link

I am doing it with empty MVC Web project.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 30, 2015

I am sorry but i am still not able to get the same repro. Are you using VS2015 or VS2013? i have tried both with no luck, but just to be sure.
compileonsave2

@vytautas-pranskunas-
Copy link

Vs2013. Its not only for me, its for all the team. Are you replacing only typescriptservices.js or something more?
I can create empty project and send it to you just tell me where.
But it just plain setup as i wrote before.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 30, 2015

can you give TypeScript 1.5-Beta on VS2013 a try? it was just released :)

@vytautas-pranskunas-
Copy link

I defenetly will. Whats the best way to install it?

1 similar comment
@vytautas-pranskunas-
Copy link

I defenetly will. Whats the best way to install it?

@vytautas-pranskunas-
Copy link

How this affects my MsBuild task? I mean I will have to update to 1.5 TS my CI server wouldn't I? I wonder can beta cause any problems to enterprise app build process?

@mhegazy
Copy link
Contributor

mhegazy commented May 1, 2015

The TypeScript targets have a property that specify which version of the compiler to use.

    <TypeScriptToolsVersion>1.4</TypeScriptToolsVersion>

if your project states 1.4 it will always build on the 1.4 compiler, even if you have 1.5 installed. so in this case you do not need to install it anywhere if you do not want to upgrade yet.

Installing the beta on production environments is up to your organizational policies.

What i am looking for is to get a way to reproduce the issue you are running into to be able to diagnose it. It would be great if you can try the same project with same setup on 1.5 to see if the problem still exists.

@vytautas-pranskunas-
Copy link

I have tried 1.5 beta:
After installing beta vs2013 throwed some errors about typescriptLanguages asking should it continue to show this error or not. After chosing "no" typescript compiler stoped generating .js files at all no matter what i did - tried to change ts version of the project and etc.
After uninstalling 1.5 i noticed that all tooling missing so i had to repair 1.4 :( after this everything went back to normal js files are generated except incorrect enums. When adding typescriptservices.js from alpha same as mentioned above happens.
Any thoughts?

@vytautas-pranskunas-
Copy link

Seems like after uninstalling 1.5 and re-installing 1.4 everything worked until vs restart. Now i get error when trying to build project because of incorrect typescript path Microsoft SDKa\TypeScript\1.4\1.4\tsc.exe
Seems like duplication of #2039
I have tried to repair typescript 1.4 but with no luck.
Any ideas how to fix this?

I was able to fix it but only by replacing TypeScript.dll taken from coworker in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TypeScript folder (uninstalling, re-installing and repairing did not helped). Looks like path was hard-coded in that .dll which might not be the best idea.

@mhegazy
Copy link
Contributor

mhegazy commented May 4, 2015

Can you share your install logs: %TEMP%\dd_TypeScript_*

@vytautas-pranskunas-
Copy link

Could you write full path to folder please?

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2015

well.. it depends where your temp folder is.. try:

echo %TEMP%

mine is at: C:\Users\mhegazy\AppData\Local\Temp

@vytautas-pranskunas-
Copy link

Give me an email where to send zip please

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2015

mhegazy at microsoft

@vytautas-pranskunas-
Copy link

We were still trying to fix that enum issue with cooworkers.
Those examples you did while trying to reproduce it - did you put enums to .d.ts file? Because while trying to fix it we noticed that enums placed in .ts files generates as expected but enums placed in defentition files generates:

  1. On build - as expected (TestEnum.One = 1 turns to 1)
  2. On save - wrong (TestEnum.One = 1 turns to TestEnum.One)

Can you try to put enums in definition file and use it other file's class and then do compile on save.

@mhegazy
Copy link
Contributor

mhegazy commented May 21, 2015

so you are still on 1.4? or have you managed to updated to 1.5? The issue did exist with 1.4, and we believe it has been fixed in 1.5.

@rwilliams-scottlogic
Copy link

It took me some digging to find the fix that was made, so here it is if anyone else also needs to patch their 1.4 typescriptServices.js: 4d14e97

It's on line 18265.

@craigktreasure
Copy link
Member Author

@mhegazy I am hitting this again with the VS 2015 RTM and TS 1.5 with my project targeting 1.5. Enum definitions are not converted to constants. Any thoughts?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 22, 2015

are they regular enums or const enums? can you share a repro?

@craigktreasure
Copy link
Member Author

They are regular enums. Same repro as the first post when i opened this issue. Workaround is to mark the enum as a const enum in the definition, but that shouldn't be necessary.

@vladima
Copy link
Contributor

vladima commented Jul 22, 2015

this is breaking change in TypeScript 1.5:

For regular enums, pre 1.5, the compiler only inline constant members, and a member was only constant if its initializer was a literal. That resulted in inconsistent behavior depending on whether the enum value is initalized with a literal or an expression. Starting with Typescript 1.5 all non-const enum members are not inlined.

@craigktreasure
Copy link
Member Author

Ouch. Good to know. I wish there had been a link to those in the 1.5 announcement post. If it was, i missed it.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 22, 2015

Good point. Will do that next release. we usually put it in the release notes: https://github.com/Microsoft/TypeScript/releases/tag/v1.5.3

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

9 participants