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

Typed to Arguments #44

Open
skorfmann opened this issue Dec 6, 2020 · 4 comments
Open

Typed to Arguments #44

skorfmann opened this issue Dec 6, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@skorfmann
Copy link

Given the following example:

      new statement
        .Iam()
        .deny()
        .to('DeletePolicy')
        .to('DeletePolicyVersion')
        .to('CreatePolicyVersion')
        .to('SetDefaultPolicyVersion')

It'd be great if the the argument for to would be fully typed, so that the editor / IDE could auto-complete permissions. I think it's fairly striaghtforward for the full permission names, but rather complicated for wildcards (e.g. .to('Delete*') to still be considered valid for Typescript. Perhaps literal types could help with that.

@skorfmann skorfmann added the enhancement New feature or request label Dec 6, 2020
@udondan
Copy link
Owner

udondan commented Dec 6, 2020

Interesting idea. But I wonder if it's good to provide the same functionality in multiple ways.

Actually, I made the to method only public, because not all actions are documented and therefore not all actions are covered with distinct toXxx methods. But I never expected it to be used like in your example. 😸 You know you can write it like this?:

new statement.Iam()
  .deny()
  .toDeletePolicy()
  .toDeletePolicyVersion()
  .toCreatePolicyVersion()
  .toSetDefaultPolicyVersion();

I'll have a look and try literal types, but I'm not sure JSII will like this. Wondering how this would be translated to other languages.

@skorfmann
Copy link
Author

You know you can write it like this?:

Hehe - I almost forgot about these methods :D - Still, I think literal types could be quite interesting for Typescript users.

I'll have a look and try literal types, but I'm not sure JSII will like this. Wondering how this would be translated to other languages.

I'm almost certain jsii won't like that :)

@udondan
Copy link
Owner

udondan commented Dec 7, 2020

Interestingly this compiles with jsii. Not sure it would be usable though. Wouldn't be the first time something passes jsii building and then throws up when imported.

But my first quick test shows literal types are of no use at all. Because, again, the to method is actually there for undocumented actions and therefore needs to allow any string. So the type would need to look like this:

type Test = 'Foo' | 'Bar' | 'and 8722 more strings here' | string;

And while code suggestion and auto-completion does work for pure literal types, with the fallback of string in the end, nothing of this does work (at least in VS Code)

It would only work if there are two seperate methods, one supporting all the literal types and one for fallback.

Still, I think literal types could be quite interesting for Typescript users.

Could you elaborate on how this is benefitial? You already get completion/suggestion for all the distinct methods which include detailed documentation on which resources and conditions can be used in conjunction.

@udondan
Copy link
Owner

udondan commented Dec 7, 2020

I prepared a PR just to see how this would look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants