Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ID-Prep] Parameter types are not preserved for optional parameters /fields with undefined in type and for required params with default value #57483

Closed
dragomirtitian opened this issue Feb 22, 2024 · 0 comments · Fixed by #57484
Labels
Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@dragomirtitian
Copy link
Contributor

dragomirtitian commented Feb 22, 2024

The [ID-prep] set of issues aligns Declaration Emit with the forthcoming Isolated Declarations feature.

🔎 Search Terms

optional parameter types not preserved

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground Link

💻 Code

type Map = {} & { [P in string]: any }
type MapOrUndefined = Map | undefined | "dummy"
export class Foo {
  constructor(
    // Type node is accurate, preserve
    public reuseTypeNode?: Map | undefined,
    public reuseTypeNode2?: Exclude<MapOrUndefined, "dummy">,
    // Resolve type node, requires adding | undefined
    public resolveType?: Map,
  ) { }
}

export function foo1(
    // Type node is accurate, preserve
    reuseTypeNode: Map | undefined = {},
    reuseTypeNode2: Exclude<MapOrUndefined, "dummy">  = {},
    // Resolve type node, requires adding | undefined
    resolveType: Map = {}, 
    requiredParam: number) {

}

🙁 Actual behavior

Parameters and fields named reuseTypeNode* have their types re-printed (and mangled) by the declaration transform even though the re-printed type is semantically equivalent to the source type.

🙂 Expected behavior

Parameters and fields named reuseTypeNode* should have their types preserved as they are written in source code

Additional information about the issue

No response

@dragomirtitian dragomirtitian changed the title [ID-Prep] Parameter types are not preserved. [ID-Prep] Parameter types are not preserved for optional parameters /fields with undefined in type and for required params with default value Feb 22, 2024
@RyanCavanaugh RyanCavanaugh added the Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases label Feb 22, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
2 participants