Skip to content

Arrow function parameters using an alias and intersection are expanded inappropriately in .d.ts #55575

Description

@webstrand

🔎 Search Terms

arrow function type alias parameters expansion intersection

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about declarations and aliases.

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.0-dev.20230830#code/JYWwDg9gTgLgBAbzgBShMBnOBfOAzNEOAIigFMBDAYxgFoMyAbMm4gbgCgOyAPSWOFQgA7DPADCAVzEQQAZSYsYARjgBeOAB4A8mBjARAGgB8ACh4AuFGkw69B4YfwVGDY3ABkibAEp17hGxuPmh4PElhGgc4KRl5RRoAJjt9IzNLa3QMFIcnPBc3T28-QKA

💻 Code

import{Props}from"react-select";exportconstCustomSelect1=<Option,>(x: Props<Option,false>&{})=>{}exportfunctionCustomSelect2<Option,>(x: Props<Option,false>&{}){}

🙁 Actual behavior

The output .d.ts incorrectly expands the imported Props alias. Note that it has incorrectly resolved the default parameter.

import{Props}from"react-select";exportdeclareconstCustomSelect1: <Option>(x: Omit<import("react-select/base/dist/react-select-base.cjs").PublicBaseSelectProps<Option,false,import("react-select").GroupBase<Option>>,"inputValue"|"menuIsOpen"|"onChange"|"onInputChange"|"onMenuOpen"|"onMenuClose"|"value">&Partial<import("react-select/base/dist/react-select-base.cjs").PublicBaseSelectProps<Option,false,import("react-select").GroupBase<Option>>>&import("react-select/dist/declarations/src/useStateManager").StateManagerAdditionalProps<Option>)=>void;exportdeclarefunctionCustomSelect2<Option>(x: Props<Option,false>&{}): void;

🙂 Expected behavior

The imported type alias Propsmust not be expanded, if the upstream package changes its defaults this will cause confusion because dependencies relying on the defaults will not be able to use the new default.

import{Props}from"react-select";exportdeclareconstCustomSelect1: <Option>(x: Props<Option,false>&{})=>void;exportdeclarefunctionCustomSelect2<Option>(x: Props<Option,false>&{}): void;

Additional information about the issue

This problem became much worse with the advent of 4.2.3, with prior version of typescript only mistakenly expanding the default argument.

Additionally this causes difficult-to-reproduce issues producing errors like

The inferred type of 'CustomSelect' cannot be named without a reference to '../../../node_modules/react-select/dist/declarations/src/useStateManager'. This is likely not portable. A type annotation is necessary.ts(2742)

because the expanded alias uses types that aren't imported.

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions