Skip to content

[isolatedDeclarations] Optional parameter in arrow function typed as imported generic type gets emitted as any #59292

@MichaelMitchell-at

Description

@MichaelMitchell-at
Contributor

πŸ”Ž Search Terms

isolated declarations transpiledeclarations any arrow

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?noCheck=true&isolatedDeclarations=true#code/JYWwDg9gTgLgBAbxgTzAUzgMQhAvnAMyghDgHICcyBuAKFrQA9JY4BjCAOwGd4AjAIZQ4AXjgAeACoAaAHwAKShAD8ALiw4psgJTqAbhGAATUbMS46QA

πŸ’» Code

import {type Foo} from 'foo';

export const bar = <T,>(foo?: Foo<T>): void => {};

πŸ™ Actual behavior

With "isolatedDeclarations": true this gets emitted as

export declare const bar: <T>(foo?: any) => void;

πŸ™‚ Expected behavior

This gets emitted as

import {type Foo} from 'foo';

export declare const bar: <T>(foo?: Foo<T>) => void;

Additional information about the issue

No response

Activity

changed the title [-][isolatedDeclarations] Optional parameter typed as imported generic type gets emitted as `any`[/-] [+][isolatedDeclarations] Optional parameter in arrow function typed as imported generic type gets emitted as `any`[/+] on Jul 16, 2024
added this to the Backlog milestone on Jul 26, 2024
a-tarasyuk

a-tarasyuk commented on Jul 27, 2024

@a-tarasyuk
Contributor

@RyanCavanaugh I've checked and created PR #59446, and the emitter seems to be working as expected. @MichaelMitchell-at, could you provide more details on the cases that cause the issue?

MichaelMitchell-at

MichaelMitchell-at commented on Jul 28, 2024

@MichaelMitchell-at
ContributorAuthor

@a-tarasyuk thank you for the fix! The only example I had found so far in our code base basically boils down to the example I provided. At the time I just worked around it by rewriting it as a function declaration.

jakebailey

jakebailey commented on Jan 17, 2025

@jakebailey
Member

For reference, this was fixed by #60195.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @a-tarasyuk@jakebailey@RyanCavanaugh@MichaelMitchell-at

      Issue actions

        [isolatedDeclarations] Optional parameter in arrow function typed as imported generic type gets emitted as `any` Β· Issue #59292 Β· microsoft/TypeScript