Skip to content

Commit

Permalink
Merge pull request #14 from gammarers/feature/type-to-interface
Browse files Browse the repository at this point in the history
feat: type to interface
  • Loading branch information
yicr authored Nov 27, 2024
2 parents 9b27726 + 040c2a8 commit 6fc217c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
57 changes: 57 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export enum ResourceNamingType {
CUSTOM = 'Custom',
}

export type ResourceAutoNaming = {
export interface ResourceAutoNaming {
readonly type: ResourceNamingType.AUTO;
}

export type ResourceDefaultNaming = {
export interface ResourceDefaultNaming {
readonly type: ResourceNamingType.DEFAULT;
}

Expand Down Expand Up @@ -64,6 +64,7 @@ export namespace ResourceNaming {
// function getValueByKey<K extends keyof MyObject>(obj: MyObject, key: K): MyObject[K] {
// return obj[key];
// }
type ResourceNamingOption = ResourceAutoNaming | ResourceDefaultNaming | {type: ResourceNamingType.CUSTOM; [key: string]: string};

// export type NamingOptions = {
// naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | {type: ResourceNaming.NamingType.CUSTOM; names: {[key: string]: string}};
Expand All @@ -79,7 +80,7 @@ export namespace ResourceNaming {
// resourceNaming?: {
// naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | {type: ResourceNaming.NamingType.CUSTOM; names: {[key: string]: string}};
// }) {
resourceNaming?: ResourceAutoNaming | ResourceDefaultNaming | {type: ResourceNamingType.CUSTOM; [key: string]: string}) {
resourceNaming?: ResourceNamingOption) {
return Object.fromEntries(
Object.entries(autoNaming).map(([name, value]) => {
return [name, (() => {
Expand Down
4 changes: 2 additions & 2 deletions test/naming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('ResouceNaming Testing', () => {
functionRoleName: `${random}-func-exc-role`,
};

type CustomNaming = {
interface CustomNaming {
readonly type: ResourceNamingType.CUSTOM;
readonly functionName: 'example-function';
readonly functionRoleName: 'example-role';
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('ResouceNaming Testing', () => {
});

it('Is Namings', () => {
const options: ResourceNamingOption = {
const options = {
type: ResourceNamingType.CUSTOM,
functionName: 'example-function',
functionRoleName: 'example-role',
Expand Down

0 comments on commit 6fc217c

Please sign in to comment.