Skip to content

Commit 0a23d95

Browse files
committed
docs: more detail on shaping the Props interfaces
1 parent 854ca74 commit 0a23d95

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

.github/instructions/languages/cdk.instructions.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,37 @@ This file provides instructions for generating, reviewing, and maintaining AWS C
2626
- For Step Functions definitions, prefer a chain-centric style where states are defined inline within `Chain.start(...).next(...)` so the execution flow reads top-to-bottom in one place. Avoid mixing a chain with many separately declared state `const`s; instead embed calls to helper functions directly in the chain when needed.
2727
- For Step Functions chain formatting, place `.start`, `.next`, `.when`, and `.otherwise` on their own lines, and give helper calls such as `.jsonata(...)` the same line-break weight so nested flow blocks are visually aligned and easy to scan.
2828
- For construct props that group resources (for example lambda functions or state machines), prefer explicit named object shapes (e.g. `{status: TypescriptLambdaFunction}`) over generic index signatures or broad maps so consumers are strongly typed to only the supported resources.
29+
- For construct props that consume grouped resources, prefer inline explicit object shapes in the props contract (for example `functions: { status: TypescriptLambdaFunction }`) over `Pick<...>` or generic map types.
30+
31+
### Good Example - Inline Explicit Shape
32+
33+
```typescript
34+
interface ApisProps {
35+
readonly functions: {
36+
readonly status: TypescriptLambdaFunction
37+
}
38+
readonly stateMachines: {
39+
readonly getMyPrescriptions: ExpressStateMachine
40+
}
41+
}
42+
```
43+
44+
### Bad Example - Hidden Contract via Pick
45+
46+
```typescript
47+
interface ApisProps {
48+
readonly functions: Pick<FunctionResources, "status" | "capabilityStatement">
49+
}
50+
```
51+
52+
### Bad Example - Generic Map
53+
54+
```typescript
55+
interface ApisProps {
56+
functions: {[key: string]: TypescriptLambdaFunction}
57+
stateMachines: {[key: string]: ExpressStateMachine}
58+
}
59+
```
2960

3061
## Code Standards
3162

@@ -36,6 +67,7 @@ This file provides instructions for generating, reviewing, and maintaining AWS C
3667
- Variables: camelCase
3768
- Stacks: Suffix with `Stack` (e.g., `CptsApiAppStack`)
3869
- Entry points: Suffix with `App` (e.g., `CptsApiApp.ts`)
70+
- CDK app entry points must follow `<app acronym><Api|Ui>[Sandbox]App` naming (e.g., `PsuApiApp`, `PsuApiSandboxApp`)
3971

4072
### File Organization
4173

0 commit comments

Comments
 (0)