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

Typescript Import function gets compiler error in Visual Studio #19337

Closed
prsmith1 opened this issue Oct 19, 2017 · 9 comments
Closed

Typescript Import function gets compiler error in Visual Studio #19337

prsmith1 opened this issue Oct 19, 2017 · 9 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@prsmith1
Copy link

This question was first posted here: https://stackoverflow.com/questions/46827184/typescript-import-function-gets-compiler-error/46827260?noredirect=1#46827260

In my Typescript I am using the import function as described here:
#12933

So my code is like:

import("../myScriptToBeImported").then((module) => {this.dosomethingWithModule(module); }).catch(this.doSomethingWithError.bind(this));

I am running this as part of an MVC project in Visual Studio with Webpack. Webpack compiles the Typescript without any errors and the project runs fine, yet for the above line the following errors are always shown in Visual Studio:

  • TS1128 (TS) Declaration or statement expected.
  • TS2391 (TS) Function implementation is missing or not immediately following the declaration.
  • TS7010 (TS) 'import', which lacks return-type annotation, implicitly has an 'any' return type.

I am using Typescript version 2.4.2. How can I get rid of these errors?

For information, my tsconfig file looks like this:

{ "compilerOptions": { "module": "esnext", "moduleResolution": "node", "noEmitOnError": true, "strict": true, "removeComments": false, "sourceMap": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], "lib": [ "es6", "dom" ], "baseUrl": ".", "experimentalDecorators": true, "emitDecoratorMetadata": true }, "exclude": [ "node_modules", "wwwroot" ], "compileOnSave": false, "buildOnSave": false }

@ghost
Copy link

ghost commented Oct 19, 2017

Use typescript@next which has support for this feature. Added by #14774.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 19, 2017

You should not need to install typescript@next. This feature was part of TS 2.4 release and [email protected] should have it.

From the description above, VS is not using TS 2.4. can you share your project file?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Oct 19, 2017
@prsmith1
Copy link
Author

Hi mhegazy - here is my csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup Label="Globals">
        <SccProjectName>SAK</SccProjectName>
        <SccProvider>SAK</SccProvider>
        <SccAuxPath>SAK</SccAuxPath>
        <SccLocalPath>SAK</SccLocalPath>
        <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    </PropertyGroup>

    <PropertyGroup>
      <TargetFramework>net462</TargetFramework>
    </PropertyGroup>
  
    <PropertyGroup>
      <!-- https://stackoverflow.com/questions/39176586/how-to-disable-typescript-compilation-in-net-core-projects -->
      <!-- Makes the TypeScript compilation task a no-op -->
      <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    </PropertyGroup>

    <ItemGroup>
      <EmbeddedResource Remove="Logging\**" />
    </ItemGroup>

    <ItemGroup>
      <None Remove="Areas\Ordering\Scripts\PatientIntake\intakeLayout.ts" />
      <None Remove="Scripts\Common\iocContainer.ts" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="AutoMapper" Version="6.1.1" />
        <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="3.0.1" />
        <PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
        <PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" />
        <PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="10.0.3.0" />
        <PackageReference Include="IdentityModel" Version="2.10.0" />
        <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.1" />
        <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
        <PackageReference Include="Microsoft.AspNet.SignalR" Version="2.2.2" />
        <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
        <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.1.4" />
        <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
        <PackageReference Include="NLog" Version="5.0.0-beta09" />
        <PackageReference Include="NLog.Web" Version="4.5.0" />
        <PackageReference Include="NLog.Web.AspNetCore" Version="4.4.1" />
        <PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" />
        <PackageReference Include="Telerik.UI.for.AspNet.Core" Version="2017.3.913" />
    </ItemGroup>
    <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
    </ItemGroup>
    <PropertyGroup>
        <CodeAnalysisRuleSet>$(SolutionDir)\Brightree.ruleset</CodeAnalysisRuleSet>
        <AssetTargetFallback>portable-net45+win8</AssetTargetFallback>
        <PostBuildEvent></PostBuildEvent>
        <UserSecretsId>a31e29fc-c241-499d-81f1-fc0e546093fe</UserSecretsId>
    </PropertyGroup>
    <ItemGroup>
        <AdditionalFiles Include="$(SolutionDir)\stylecop.json" />
    </ItemGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
        <TreatSpecificWarningsAsErrors />
    </PropertyGroup>
    <ItemGroup>
        <Folder Include="Areas\ARManagement\Controllers\" />
    </ItemGroup>
    <ItemGroup>
      <TypeScriptCompile Include="Areas\Ordering\Scripts\PatientIntake\intakeLayout.ts" />
      <TypeScriptCompile Include="Scripts\Common\iocContainer.ts" />
    </ItemGroup>

    <ItemGroup>
      <Content Update="web.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </Content>
    </ItemGroup>

    <ItemGroup>
      <None Update="nlog.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.Load.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.Master.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.Prod.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.QA.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.QAHot.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.StageA.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.StageB.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
      <None Update="web.StageC.config">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      </None>
    </ItemGroup>

    <ProjectExtensions>
       <VisualStudio><UserProperties appsettings_1Production_1json__JSONSchema="" Properties_4launchSettings_1json__JSONSchema="" appsettings_1QA_1json__JSONSchema="" appsettings_1json__JSONSchema="" package_1json__JSONSchema="" /></VisualStudio>
    </ProjectExtensions>

</Project>

@mhegazy
Copy link
Contributor

mhegazy commented Oct 23, 2017

I am unable to reproduce this locally with this file. can you share the full project, or a sample project that shows the issue?

Also noticed that your tsconfig.json is not referenced from the project file above, is this the same project?

@prsmith1
Copy link
Author

The tsconfig is included in the project. I'm not sure why it does not show in the proj file.

I should mention that other developers working on the exact same project do not get this error, so it must be something to do with my local environment.

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Oct 27, 2017

@prsmith1 Might you have the wrong TypeScript settings configured in your .csproj?
Even with <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>, the project settings tools version will still affect the language features recognized by the IDE.

For example
image

Compared to
image

I see that you have <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion> configured, but you may not have installed a recent release of TypeScript tools for Visual Studio.

@prsmith1
Copy link
Author

@aluanhaddad I have tried '2.3' and 'Use latest available' (we are using 2.4), but it didn't make any difference. Looking at my extensions, the 'TypeScript Build for Microsoft Visual Studio' and 'TypeScript for Microsoft Visual Studio' extensions are both on 15.3.10723.1 and are set to auto update, so I think they're okay too.

@aluanhaddad
Copy link
Contributor

Well, it will not work with '2.3' and I was thinking that you might have an older version of the SDK installed and that 'latest' might be mapping to '<2.4'.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

4 participants