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

Reject Props arguments that have a property with the same name as a function parameter #268

Closed
dstufft opened this issue Oct 22, 2018 · 0 comments · Fixed by #273
Closed

Comments

@dstufft
Copy link
Contributor

dstufft commented Oct 22, 2018

Given a signature like:

export interface MyProps {
    fooBar: string;
}

export class MyClass {
    public doAThing(fooBar: string, props: MyProps) {
    }
}

That works fine in TypeScript, but in languages where we want to "lift" a final props parameter into arguments to the function itself (like for example, keyword arguments in Python), this will fail because it will generate code like:

class MyClass:
    def do_a_thing(foo_bar: str, *, foo_bar):
        ...

Which is an error, because there is a collision on the "real" function parameter names, and the lifted parameter names, and you can't have two parameters with the same name.

Ideally the JSII compiler would reject this method signature, and require one of the two names to change. Alternatively, if there were a way to either opt-in or opt-out of the lifting of MyProps into keyword arguments, that could also allow people a way to resolve this without requiring them to choose different names, they would just not lift that particular data type into keyword arguments.

rix0rrr pushed a commit that referenced this issue Oct 22, 2018
Restrict the usage of datatype parameters in functions, so that
languages with keyword argument support can inline datatype parameters
into the function declaration. This means it cannot share any field
names with remaining function argument names.

Fixes #268.
rix0rrr added a commit that referenced this issue Oct 23, 2018
Restrict the usage of datatype parameters in functions, so that
languages with keyword argument support can inline datatype parameters
into the function declaration. This means it cannot share any field
names with remaining function argument names.

Fixes #268.
rix0rrr pushed a commit that referenced this issue Oct 23, 2018
* **jsii:** use base interfaces for 'datatype' property ([#265](#265)) ([1c56902](1c56902)), closes [#264](#264)
* **jsii:** use default jsx compiler options ([#261](#261)) ([bf1f586](bf1f586)), closes [aws/aws-cdk#830](aws/aws-cdk#830)
* match behavioral interface to 'I'-prefix ([#271](#271)) ([03103f3](03103f3))
* require distinct argument and property names ([#272](#272)) ([4d2f268](4d2f268)), closes [#268](#268)
@rix0rrr rix0rrr mentioned this issue Oct 23, 2018
rix0rrr added a commit that referenced this issue Oct 23, 2018
Bug Fixes
=======

* **jsii:** use base interfaces for 'datatype' property ([#265](#265)) ([1c56902](1c56902)), closes [#264](#264)
* **jsii:** use default jsx compiler options ([#261](#261)) ([bf1f586](bf1f586)), closes [aws/aws-cdk#830](aws/aws-cdk#830)
* match behavioral interface to 'I'-prefix ([#271](#271)) ([03103f3](03103f3))
* require distinct argument and property names ([#272](#272)) ([4d2f268](4d2f268)), closes [#268](#268)
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 a pull request may close this issue.

1 participant