Visual Studio 2022 implicit TypeScript references


I’m trying to open a Visual Studio project which works fine in VS2019 in VS2022. The latter doesn’t seem to understand types from my other files and third party libraries, similar to this question, e.g:

file1.ts

export class Hedgehog {
    spikes() {
        return 100;
    }
}

file2.ts
var h = new Hedgehog(); // Could not find symbol Hedgehog

// Despite installing nuget packade knockout.TypeScript.DefinitelyTyped
var five = ko.observable(5); // Could not find symbol ko

All my .ts files have build action “TypeScriptCompile”.

I’ve installed the nuget package for the ts version that’s being used:

<package id="Microsoft.TypeScript.MSBuild" version="3.6.4" targetFramework="net461" developmentDependency="true" />

Here are the relevant parts of the .csproj

<Import Project="..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.props" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.props')" />
...
<TypeScriptToolsVersion>3.3</TypeScriptToolsVersion>
<TypeScriptSkipLibCheck>True</TypeScriptSkipLibCheck>
...
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptJSXEmit>None</TypeScriptJSXEmit>
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptModuleKind>None</TypeScriptModuleKind>
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>
<TypeScriptOutFile />
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>True</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />
...
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.props'))" />
  <Error Condition="!Exists('..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.targets" Condition="Exists('..\packages\Microsoft.TypeScript.MSBuild.3.6.4\build\Microsoft.TypeScript.MSBuild.targets')" />

Did I miss anything obvious?

Leave a Reply

Your email address will not be published. Required fields are marked *