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: Types for CommandManager.on's callback's arguments were lost between 1.36.5 and 1.37.5 #5742

Open
shepmaster opened this issue Feb 10, 2025 · 0 comments

Comments

@shepmaster
Copy link

shepmaster commented Feb 10, 2025

Describe the bug / Current Behavior

Code like editor.commands.on('afterExec', ({ editor, command }) => { /* ... */ }) no longer knows the type of editor (Ace.Editor) or command (Ace.Command).

Expected Behavior

Code like editor.commands.on('afterExec', ({ editor, command }) => { /* ... */ }) knows the type of editor (Ace.Editor) or command (Ace.Command).

Reproduction Steps

Create a basic TypeScript project

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

package.json

{
  "name": "repro",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ace-builds": "1.36.5",
    "typescript": "^5.7.3"
  }
}

index.ts

import { Ace } from 'ace-builds';

// ==========
// https://stackoverflow.com/a/58779181/155423
type IsAny<T> =
  unknown extends T ? T extends {} ? T : never : never;

type NotAny<T> =
  T extends IsAny<T> ? never : T;

function notAny<T>(x: NotAny<T>) { }
// ==========

function example(editor: Ace.Editor) {
  editor.commands.on('afterExec', ({ editor, command }) => {
    notAny(editor);
    notAny(command);
  });
}

Run the project

pnpm tsc index.ts

Upgrade to 1.37.5, run project again

pnpm tsc index.ts
index.ts:16:12 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

16     notAny(editor);
              ~~~~~~

index.ts:17:12 - error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

17     notAny(command);
              ~~~~~~~

Possible Solution

No response

Additional Information/Context

Going only by the changelog entry, the changes from @mkslanc in #5427 seem likely to be relevant.

Ace Version / Browser / OS / Keyboard layout

Ace 1.37.5 / TypeScript 5.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant