Skip to content

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

@dstufft

Description

@dstufft

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions