View Issue Details

IDProjectCategoryView StatusLast Update
0005844Talerwallet (TS core)public2020-09-09 09:30
ReporterFlorian Dold Assigned ToFlorian Dold  
PrioritylowSeveritytweakReproducibilityhave not tried
Status assignedResolutionopen 
Summary0005844: use wrapper types instead of raw strings
DescriptionInstead of using e.g.

  contractHash: string

we should have wrapper types for everything. As TS doesn't support nominal typing (but only structural typing), we need to name the member of the wrapper structure according to its type. Thus the above becomes

  contractHash: HashCode

which is just an alias for

  contractHash: { sha512Hash: string }

To implement this without having to duplicate all structs, the JSON validator (checkable.ts) needs to support wrapping parsed JSON in these wrappers.
TagsNo tags attached.

Activities

Florian Dold

2020-09-08 18:12

manager   ~0016932

Instead of wrapper types, we can use flavors, which are compile-time only:

interface Flavoring<FlavorT> {
  _type?: FlavorT;
}
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;

(via https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/)

This allows implicit conversions between the "unflavored" type and flavored type, but prevents mixups between different flavored types.

Issue History

Date Modified Username Field Change
2019-08-18 21:07 Florian Dold New Issue
2019-08-18 21:07 Florian Dold Status new => assigned
2019-08-18 21:07 Florian Dold Assigned To => Florian Dold
2020-09-04 12:16 Florian Dold Priority normal => low
2020-09-05 13:53 Christian Grothoff Severity minor => tweak
2020-09-08 18:12 Florian Dold Note Added: 0016932
2020-09-09 09:30 Florian Dold Category wallet (WebExtensions) => wallet (TS core)