Skip to content

Optional any is typed as a required any. #230

Closed

Description

@rix0rrr

Originally reported here:

aws/aws-cdk#714

The issue is that the declaration was:

interface Permission {
    sourceAccount?: any;
}

Which got translated into the following JSII:

        {
          "name": "sourceAccount",
          "type": {
            "primitive": "any"
          }
        },

I.e., the "optional" part of it got lost.

Activity

  1. self-assigned this
    on Sep 18, 2018
  2. RomainMuller commented on Sep 18, 2018

    @RomainMuller
    Contributor

    I found the bug's cause (compiler would not consider the declaration.questionMark, and would only report as optional the union types including null and/or undefined). This actually makes me wonder if we should treat all any as optional (aka - if the type is any, then it is optional any)?

  3. added a commit that references this issue on Sep 18, 2018
    74770c7
  4. RomainMuller commented on Sep 18, 2018

    @RomainMuller
    Contributor

    Well the PR #237 includes code to make any optional everywhere it is found (because that is how TypeScript thinks of it).

  5. eladb commented on Sep 18, 2018

    @eladb
    Contributor

    But what happens if there’s an “any” argument in the middle of a signature? Optional arguments are only allowed at the end.

  6. RomainMuller commented on Sep 19, 2018

    @RomainMuller
    Contributor

    Well - optional is a type attribute, not a parameter attribute. In the general sense, it denotes nullability (and in fact, TypeScript lets you put optional arguments in any place you want).

  7. added a commit that references this issue on Sep 19, 2018
    91074f3
  8. added a commit that references this issue on Sep 20, 2018
  9. eladb commented on Sep 20, 2018

    @eladb
    Contributor

    screen shot 2018-09-21 at 12 38 57 am

  10. rix0rrr commented on Sep 21, 2018

    @rix0rrr
    ContributorAuthor

    Yes, there is (somewhat) of a difference between x?: l2 and x: l2 | undefined

  11. RomainMuller commented on Oct 26, 2018

    @RomainMuller
    Contributor

    That is in large parts because jsii models optional as a type attribute, and not as a parameter attribute...

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

Metadata

Metadata

Assignees

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