“jQueryStatic<TElement extends Node>”类型的值不可调用

Value of type “jQueryStatic<TElement extends Node>” is not callable

问题: Visual Studio IntelliSense 对 $ 大喊:Value of type “jQueryStatic<TElement extends Node>” is not callable

示例代码$的所有实例,真的):

const emaildiv = $("<div>", { "class": "email-item" });
$(containerid).append(emaildiv);

设置:

tsconfig.ts:

 {
   "compilerOptions": {
     "lib": [ "es2015", "es2015.iterable", "dom" ],
     "noImplicitAny": true,
     "noEmitOnError": true,
     "removeComments": false,
     "sourceMap": true,
     "target": "es5"
   },
   "files": [
     // a bunch of local files...
   ],
   "compileOnSave": true
 }

.csproj:

   <PropertyGroup>
     <TargetFramework>netcoreapp2.0</TargetFramework>
     <TypeScriptToolsVersion>2.3</TypeScriptToolsVersion>
   </PropertyGroup>

   <ItemGroup>
     <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
   </ItemGroup>

   <ItemGroup>
     <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
   </ItemGroup>

   <ItemGroup>
     <!-- other .ts files -->
     <TypeScriptCompile Include="Scripts\Scripts.ts" />
   </ItemGroup>

   <ItemGroup>
     <Folder Include="wwwroot\scripts\" />
   </ItemGroup>

 </Project>

一切都在构建并且运行良好。有人知道吗?

Value of type “jQueryStatic” is not callable

由类型定义和 typescript 编译器版本之间的兼容性问题引起。

修复

升级到最新的 typescript (2.5.2) 并确保 jquery.d.ts(或 @types/jquery)是最新的。

事实证明,问题又出在 Resharper (Value of type "JqueryStatic" is not callable) 上。这是我所做的一切的列表:

  • 根据 basarat 的回答更新 TypeScript 和 jquery.d.ts
  • 将 Resharper 更新到 2017.2(即最新版本)
  • ReSharper → 选项 → 常规 → 清理缓存 ()
  • ReSharper → 选项 → 代码编辑 → TypeScript → 检查 → TypeScript 语言级别 - 最新可用
  • 重启Visual Studio