iam-floyd
iam-floyd copied to clipboard
test exporting literal types
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'));
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'>;

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.