My primary idea is to use Typescript ecosystem as an "editor" to create markdown SPECifications based on "domain" examples - the type safest possible way, with autocomplete and "notifications" for compilation errors
So far I have this code with stated PROBLEMs:
/* TYPES.ts */
// a SPEC-ification TTL (implementation is omited, it is only prototype for now)
declare function SPEC (docs: TemplateStringsArray, ...domainExamples: Glossary[]): ExFnc
type ExFnc = (optionalOverloadingDomainExample?: Object) => string
// ... rest of types are omited here - pls see them by link to TS Playground
/* DOMAIN_GLOSSARY.ts */
// At = Attribute
// roAt = read-only Attribute
// Ac = Action
type Glossary
// Label Example 1 Example N
= At <`Url`, `system.org/login`>
| At <`User Name`, `[email protected]` | `[email protected]`>
| At <`Password`, `existing` | `invalid`>
| Ac <`Login`>
| roAt <`Error message`, `Invalid User Name or Password`>
/* SPECIFICATION_BY_EXAMPLE.ts */
const S1_Alt2 = SPEC
`
## Alternative scenario: Invalid login
- Given
- ${`Url: system.org/login`}
- When
- ${`User Name: [email protected]`}
- ${`Password: invalid`}
- ${`Login`}
- Then
- ${`Error message? Invalid User Name or Password`}
`
/* TEST_CASES.ts */
// Case here is OK Scenario call - because there STILL is "original" domain Example
S1_Alt2 ()
// Case here is OK Scenario call - because "correctly" overloading original domain Example
S1_Alt2 ({
'User Name': `[email protected]`,
'Password': `existing`
})
// Case here is KO Scenario call - because "INcorrectly" overloading original domain Example
// and I expected stated "approximate" compile errors
S1_Alt2 ({
'Useeer Name': `[email protected]`,
// Object literal may only specify known properties, and ''Useeeer Name'' does not exist in type '...'
'Password': `exiiisting`,
// Type '"exiiisting"' is not assignable to type '"existing"'.
// The expected type comes from property 'Password' which is declared here on type '...'
'Home page title':
// Object literal may only specify known properties, and ''Home page title'' does not exist in type '...'
// (pls note: this is because `Home page title...` was NOT interpollated in const S1_Alt1 = SPEC<uiLogin>`...` )
})
TS playground with complete code and types so far
1. PROBLEM - type ExFnc:
- how to declare its single param type
Object- so that Object properties:- can only be from Glossary Attributes but not Actions
- can only be from interpollated ones
- have to be optional
- and all that any deep level
- I think this PROBLEM alone - is big CHALLANGE!!!
2. PROBLEM - concise "Glossarifying"
- I am looking for more concise syntax to "Glossarify" - based on interfaces
- resp. how transform interfaces to "type safe" tagged template literals ?
- all function members of interface should be transformed as "actions" in TTL
- and all NONfunction members as "attributes"
3. PROBLEM - type safe call of S1_Alt2 ({ with autocomplete })
- pls see object literal in the last call of
S1_Alt2- 'Useeer Name' property or 'exiiisting' value - here I expect compile errors - or if
Loginstated here - I expect compile error too- because Actions can't be "overloaded" (only Attributes can) - else we have "ANOTHER/STRANGE" "Scenario" (imagine
CancelAction in Scenario call !!!)
- because Actions can't be "overloaded" (only Attributes can) - else we have "ANOTHER/STRANGE" "Scenario" (imagine
- or if
Home page title...stated here - I expect compile error too- because Attribute
Home page title...was NOT interpollated in original const S1_Alt2 = SPEC`...`
- because Attribute
- and all Attributes should be optional but with autocomplete here
- because they are already stated in const S1_Alt2
Pls any suggestions ?
FOR THIS ANSWER - ALL CREDITS HERE GOES TO @captain-yossarian
(note: there is still big CHALLENGE with 1. PROBLEM - but rest is already on the right track :)
H I N T: for big picture pls start reading from /* I. (domain) GLOSSARY.ts */ part