[ID-Prep] Parameter types are not preserved for optional parameters /fields with undefined in type and for required params with default value #57483
Copy link
Copy link
Closed
Labels
Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
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
💻 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
Metadata
Metadata
Assignees
Labels
Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Activity
[-][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[/+]