镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[isolatedDeclarations] function expressions as an argument to a function call that is exported are reported as needing an annotation #62085

Description

🔎 Search Terms

"isolatedDeclarations", "function return type", "exported variable"

🕗 Version & Regression Information

  • This changed between versions 5.6.3 and 5.7.3

⏯ Playground Link

https://www.typescriptlang.org/play/?isolatedDeclarations=true#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQokscA3ivsBAHZwC+cREuRAQARgA9aDcNHhsxqLFABuSvgOKkyIiQFpKeGFLpZxTeLm6p4AYRKQuWLvAC8cBUtVQAFN4CUcC4AfKx0cHCUMACuUDwAPEFxAPRB9Lx+9CZmsnCWXNZwMAAWwFwA5oHsMJxc3gRRXBzccP6h4ZExPHYyjs5pGXRAA

💻 Code

import * as React from 'react';
import { action } from 'mobx';
import { observer } from 'mobx-react';

export const Component = observer(() => {
  return <></>;
});

export const thing = action(function () {
  return Component;
});

🙁 Actual behavior

import * as React from 'react';
import { action } from 'mobx';
import { observer } from 'mobx-react';

export const Component = observer(() => {
             ~~~~~~~~~ Variable must have an explicit type annotation with --isolatedDeclarations.
                                  ~~~~~ Function must have an explicit return type annotation with --isolatedDeclarations.
  return <></>;
});

export const thing = action(function () {
             ~~~~~ Variable must have an explicit type annotation with --isolatedDeclarations.
                            ~~~~~~~~ Function must have an explicit return type annotation with --isolatedDeclarations.
  return Component;
});

🙂 Expected behavior

import * as React from 'react';
import { action } from 'mobx';
import { observer } from 'mobx-react';

export const Component = observer(() => {
             ~~~~~~~~~ Variable must have an explicit type annotation with --isolatedDeclarations.
  return <></>;
});

export const thing = action(function () {
             ~~~~~ Variable must have an explicit type annotation with --isolatedDeclarations.
  return Component;
});

Additional information about the issue

The function expressions are not directly exported so they should not be reported on at all.
This is causing ts-fix to insert many unnecessary annotations when codemodding the codebase at Canva because there's no way for it to tell that annotating the variable will silence the error on the function -- so it adds both annotations.

Activity

  1. KisaragiEffective commented on Jul 18, 2025

    @KisaragiEffective

    Here's self-contained example based on yours:

    export declare function observer<T>(component: T): T;
    export declare function action<T>(fn: T): T;
    
    // ok
    () => 1;
    // also ok
    observer(() => 1);
    
    // error on both variable and function
    export const named = observer(() => 1);
    // also error on both variable and function
    export const thing = action(() => named);
    // error on variable, but not function
    export const thing2 = action((): typeof named => named);

    maybe changed in #59282 , according history from https://github.com/microsoft/TypeScript/blame/2778e84ed88894156e2c5a17d74a25c73cc96ffe/tests/baselines/reference/isolatedDeclarationErrors.errors.txt#L3

  2. added a commit that references this issue on Jul 25, 2025
    b3bebe3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Domain: flag: isolatedDeclarationsRelated to the --isolatedDeclarations compiler flagHelp WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions