iam-floyd icon indicating copy to clipboard operation
iam-floyd copied to clipboard

test exporting literal types

Open udondan opened this issue 5 years ago • 1 comments

This code compiles with a couple thousand of warnings like this:

lib/generated/x-ray.ts:467:1 - message JSII9998: Unsupported TypeAliasDeclaration node. This declaration will not be accessible from other languages.

467 export type XrayActions = XrayActionsList | XrayActionsWrite | XrayActionsPermissionsManagement | XrayActionsRead | XrayActionsTagging;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

But the package builds and can be imported, tested with Python. Of course, this won't work in any other language than TypeScript.

The types are not implemented in any method. But could be used like this:

function t(action: statement.IamActions): string {
  return action
}

new statement.Iam() //
      .allow()
      .to(t('DeletePolicy'));

udondan avatar Dec 07 '20 10:12 udondan

What I meant was more along the lines of this:

type Actions =
  | 'CreateTable'
  | 'CreateIndex'
  | 'CreateBucket'

type MatchIamAction<T extends string> =
  string extends T
  ? Record<string, string>
  : T extends `${infer Start},${infer Rest}`
  ? {[k in Start | keyof MatchIamAction<Rest>]: string}
  : T extends `${infer Start}`
  ? {[k in Start]: string}
  : {};

type P = MatchIamAction<'CreateTable'>;

type C = MatchIamAction<'Create*,ListTable'>;

Screenshot 2020-12-07 at 11 38 31

However - after some googling I don't think that pattern matching is working the way. I was hoping for. I wasn't able to expand Create* to the full action in the types.

skorfmann avatar Dec 07 '20 10:12 skorfmann