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

Type Inference forcing to destructure object #6462

Closed
thoroc opened this issue May 13, 2024 · 5 comments
Closed

Type Inference forcing to destructure object #6462

thoroc opened this issue May 13, 2024 · 5 comments
Labels
🐛 bug Something isn't working community-request requested by community members 🛠️ compiler Compiler

Comments

@thoroc
Copy link

thoroc commented May 13, 2024

I tried this:

I have a class as follow:

pub class MyHandler impl cloud.IFunctionHandler {
  _credentials: dynamodb.Credentials?;

  new(options: types.SessionHandlerOptions) {
    this._credentials = options.credentials;
  }

The struct for the options has the following:

pub struct SessionHandlerOptions {
  ...
  credentials: dynamodb.Credentials?;
}

In a follow up method on the class I can do:

    let client = new dynamodb.Client({
      tableName: this._table.tableName, 
      credentials: {
        accessKeyId: this._credentials?.accessKeyId!, 
        secretAccessKey: this._credentials?.secretAccessKey!
      }
    });

But not this

    let client = new dynamodb.Client({
      tableName: this._table.tableName, 
      credentials: this._credentials
    });

I am still trying to find my way around so apologies if it seems that I am writing the code the wrong way around.

This happened:

I am getting this error message:

Expected type to be "Credentials?", but got "Credentials?" instead

I expected this:

To be able to assign the class property instead of having to destructure it and create a new object.

Is there a workaround?

No response

Anything else?

Potential duplicate.

Wing Version

0.73.41

Node.js Version

20.11.0

Platform(s)

MacOS

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@thoroc thoroc added the 🐛 bug Something isn't working label May 13, 2024
@ShaiBer ShaiBer added the community-request requested by community members label May 20, 2024
@skyrpex
Copy link
Contributor

skyrpex commented May 21, 2024

@thoroc Is that still an issue with @winglibs/dynamodb 0.1.11? Previously, there were two Credentials interfaces and now there's only one.

I think it's expected that two different interfaces can't be mixed, even if they have the same properties. I may be wrong, though. @MarkMcCulloh is that correct?

Anyways, the error message is confusing if both interfaces are named the same. Any ideas to improve it? Maybe referring to the filename where they are declared, if the names are the same?

@MarkMcCulloh
Copy link
Contributor

I think it's expected that two different interfaces can't be mixed @MarkMcCulloh is that correct?

Yeah, although I opened an issue to possibly change that behavior (for structs) #6467

@thoroc
Copy link
Author

thoroc commented May 21, 2024

referring

I'll need to double check, although as per advice I've moved away from creating a client directly.

I'll test it at first opportunity.

@thoroc
Copy link
Author

thoroc commented May 22, 2024

@skyrpex The changes to the dynamodb has fixed the discrepancy. Thank you.

@thoroc thoroc closed this as completed May 22, 2024
@staycoolcall911
Copy link
Contributor

Nice! Thanks for following up @thoroc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working community-request requested by community members 🛠️ compiler Compiler
Projects
Status: Done
Development

No branches or pull requests

6 participants