Skip to content

Provide typing information for destructuring parameters#621

Closed
Maximkaaa wants to merge 3 commits intoTypeStrong:masterfrom
Maximkaaa:destruct_types
Closed

Provide typing information for destructuring parameters#621
Maximkaaa wants to merge 3 commits intoTypeStrong:masterfrom
Maximkaaa:destruct_types

Conversation

@Maximkaaa
Copy link
Copy Markdown

Currently if a parameter of function or constructor is a distructured object, the type of the parameter is always rendered as "object", even if the type is explicetely stated. My use case for typed destructured parameters is like this:

interface InitializationParameters {
  param: string;
}

class MyClass {
  constructor({param = "defaultValue"}: InitializationParameters) { ... }
}

After converting this code to reflections, there is no typing information for "__namedParameters" arguments, so it's impossible to show argument type with doc template. This is how the result looks currently (it is simple example from the test case added in this PR):

/**
 * A function with a destructuring argument that implements interface.
 */
export function functionWithTypedDestr({name}: classes.INameInterface) { }

typed_desctr

This PR fixes the lack of typing information of destructured argument. A follow up default themes PR actually uses this information to show the type.

Unfortunately this PR does not fix the same issue when type alias is used instead of interface for type definition. But since recomended way in this case is using interface, this solution should suffice for a while.

@Maximkaaa
Copy link
Copy Markdown
Author

Default theme PR: TypeStrong/typedoc-default-themes#51

@brendo
Copy link
Copy Markdown

brendo commented Nov 16, 2017

This would be extremely useful, almost all projects I work with use "object bags" and destructuring for methods, so it's a little disheartening having to dive back into the code to understand further.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants