Carthax
Carthax

Reputation: 119

Cannot compile my webapp due to error in index.d.ts

I walked away from some code three days ago and it was working perfectly. This afternoon, I logged in to see this error:

Build:Type '"button" | "view" | "altKey" | "bubbles" | "cancelable" | "changedTouches" | "ctrlKey" | "detail" | "eventPhase" | "metaKey" | "pageX" | "pageY" | "shiftKey" | "char" | "charCode" | ... 13 more ... | "touches"' does not satisfy the constraint '"button" | "code" | "view" | "y" | "altKey" | "bubbles" | "cancelable" | "changedTouches" | "ctrlKey" | "detail" | "eventPhase" | "metaKey" | "pageX" | "pageY" | "shiftKey" | "char" | ... 54 more ... | "DOM_KEY_LOCATION_STANDARD"'. Exemptions  C:\Users\bh05164\node_modules\@types\jquery\index.d.ts  8155    

When I double-click that error, I get this line of text:

interface Event<TTarget = EventTarget,
        TData = null> extends Partial<Pick<PointerEvent & KeyboardEvent & TouchEvent, 'altKey' | 'bubbles' | 'cancelable' |
        'changedTouches' | 'ctrlKey' | 'detail' | 'eventPhase' | 'metaKey' | 'pageX' | 'pageY' | 'shiftKey' | 'view' |
        'char' | 'charCode' | 'key' | 'keyCode' | 'button' | 'buttons' | 'clientX' | 'clientY' | 'offsetX' | 'offsetY' |
        'pointerId' | 'pointerType' | 'screenX' | 'screenY' | 'targetTouches' | 'toElement' | 'touches'>> {

...and 'altKey' is highlighted.

Nothing changed in my code, and the best answer I've gotten from Google is "update TypeScript." I have installed the latest version, but there has been no change.

How do I get rid of this error?

Upvotes: 2

Views: 4562

Answers (4)

SmallWorld
SmallWorld

Reputation: 233

I fixed this issue by updating my types that I was downloading through libman. Then I had to right click on libman, clear and then restore packages. This will regenerate all the files.

I also updated my Microsoft.TypeScript.MSBuild in nuget package.

Upvotes: 0

Matthew Peterson
Matthew Peterson

Reputation: 1205

Whenever I've seen this message it had to do with an incorrect index.d.ts file.

In my package.json I defined several definitely typed dev dependencies.

{
    "version": "1.0.0",
    "name": "asp.net",
    "private": true,
    "devDependencies": {
        "@types/kendo-ui": "2018.2.4",
        "@types/jqueryui": "1.12.7"
    }
}

Unbeknownst to me, the kendo-ui type file had a dependency on the JQuery type file.
However, the JQuery type definition that kendo-ui 2018.2.4 was created against wasn't getting pulled into my project.

Since the dependency just specified JQuery, it would grab the latest version of the JQuery DefinitelyTyped file and use it in my project. This file was not compatible with kendo-ui 2018.2.4 so it would result in the error:

Build:Type '"button" | "view" | "altKey" | "bubbles" | "cancelable" | "changedTouches" | "ctrlKey" | "detail" | "eventPhase" | "metaKey" | "pageX" | "pageY" | "shiftKey" | "char" | "charCode" | ... 13 more ... | "touches"' does not satisfy the constraint '"button" | "code" | "view" | "y" | "altKey" | "bubbles" | "cancelable" | "changedTouches" | "ctrlKey" | "detail" | "eventPhase" | "metaKey" | "pageX" | "pageY" | "shiftKey" | "char" | ... 54 more ... | "DOM_KEY_LOCATION_STANDARD"'.

You can verify this by checking the file that gets pulled into your node_modules folder.

In order to solve this error, I had to upgrade my kendo-ui version to one that was compatible with the latest JQuery DefiantlyTyped version.

{
    "version": "1.0.0",
    "name": "asp.net",
    "private": true,
    "devDependencies": {
        "@types/kendo-ui": "2019.2.0",
        "@types/jqueryui": "1.12.7"
    }
}

I stumbled on this solution after reading this GitHub issue.

Upvotes: 1

Libor Kubala
Libor Kubala

Reputation: 11

Visual Studio build error TS2344 in jquery.d.ts

  1. Install Nuget packages Microsoft.TypeScript.MSBuild version 3.5.3 - must be version 3.5.3 or less

  2. Visual Studio Marketplace:

<PropertyGroup> 
  <TargetFramework>...</TargetFramework>
  <AssemblyName>...</AssemblyName>
  <TypeScriptToolsVersion>3.5</TypeScriptToolsVersion>
</PropertyGroup>

Upvotes: 1

Carthax
Carthax

Reputation: 119

The solution, at least in this case, was to delete my code completely and then re-download it from BitBucket.

All is working, now. No idea why it broke.

Upvotes: 0

Related Questions