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

fix: preserve function params type if possible #14694

Merged
merged 2 commits into from Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/babel-plugin-transform-parameters/src/params.ts
Expand Up @@ -187,6 +187,7 @@ export default function convertFunctionParams(
body.push(defNode);
} else if (param.isObjectPattern() || param.isArrayPattern()) {
const uid = path.scope.generateUidIdentifier("ref");
uid.typeAnnotation = param.node.typeAnnotation;

const defNode = t.variableDeclaration("let", [
t.variableDeclarator(param.node, uid),
Expand Down
@@ -0,0 +1,13 @@
type Point = {
x: number;
y: number;
};

function value({ x, y }: Point) {
return x * y;
}

function valueWithDefault({ x, y }: Point = {}) {
return x * y;
}

@@ -0,0 +1,18 @@
type Point = {
x: number;
y: number;
};

function value(_ref: Point) {
var x = _ref.x,
y = _ref.y;
return x * y;
}

function valueWithDefault() {
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
x = _ref2.x,
y = _ref2.y;

return x * y;
}