Microsoft/TypeScript
在 GitHub 查看[isolatedDeclarations] function expressions as an argument to a function call that is exported are reported as needing an annotation
Open
#62,085 创建于 2025年7月17日
Domain: flag: isolatedDeclarationsFix AvailableHelp WantedPossible Improvement
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
🔎 Search Terms
"isolatedDeclarations", "function return type", "exported variable"
🕗 Version & Regression Information
- This changed between versions 5.6.3 and 5.7.3
⏯ Playground Link
💻 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.