Skip to content

tsgo produces TS2775 for function with assertion function assigned to a property but tsc does not #1774

@wincent

Description

@wincent

Steps to reproduce

Create a new TS project:

npm init -y
npm add @typescript/native-preview
npm add typescript
echo '{}' > tsconfig.json

Create a file, demo.ts:

function example() {}

example.isFoo = function isFoo(value: string): asserts value is 'foo' {
  if (value !== 'foo') {
    throw new Error('Not foo');
  }
};

example.isFoo('test');

Behavior with typescript@5.8

Run node_modules/.bin/tsc — no errors.

Behavior with tsgo

Run node_modules/.bin/tsgo — see:

demo.ts:9:1 - error TS2775: Assertions require every name in the call target to be declared with an explicit type annotation.

9 example.isFoo('test');
  ~~~~~~~~~~~~~

  demo.ts:3:1 - 'isFoo' needs an explicit type annotation.
      3 example.isFoo = function isFoo(value: string): asserts value is 'foo' {
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      4   if (value !== 'foo') {
        ~~~~~~~~~~~~~~~~~~~~~~~~
    ...
      6   }
        ~~~
      7 };
        ~


Found 1 error in demo.ts:9

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions