winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.73k stars 185 forks source link

Type Inference forcing to destructure object #6462

Closed thoroc closed 3 weeks ago

thoroc commented 1 month ago

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

skyrpex commented 3 weeks ago

@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 commented 3 weeks ago

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) https://github.com/winglang/wing/issues/6467

thoroc commented 3 weeks ago

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 commented 3 weeks ago

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

staycoolcall911 commented 3 weeks ago

Nice! Thanks for following up @thoroc