microsoft / microsoft/TypeScript

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

Abierto
#62,085 1 comentario 2 reacciones 1 asignado Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: flag: isolatedDeclarations Help Wanted Possible Improvement
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

### 🔎 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

```ts
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

```ts
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

```ts
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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.