sam-goodwin / punchcard

Type-safe AWS infrastructure.
Apache License 2.0
507 stars 20 forks source link

feat(core): use interfaces to assign names to computed types #85

Closed sam-goodwin closed 4 years ago

sam-goodwin commented 4 years ago

We compute types everywhere in Punchcard which can result in some gnarly type signatures that are quite difficult to read.

This happens because we use type aliases instead of using interfaces.

//before
export type ReadOnly<PKey extends keyof A, SKey extends keyof A | undefined, A extends Attributes> = Omit<Client<PKey, SKey, A>, 'put' | 'putBatch' | 'delete' | 'update'>;
// now
export interface ReadOnly<PKey extends keyof A, SKey extends keyof A | undefined, A extends Attributes> extends Omit<Client<PKey, SKey, A>, 'put' | 'putBatch' | 'delete' | 'update'> {}

A type alias has no identifier at compile time. It is simply an alias/pointer to another type. This results in ugly names, especially when using computations like Omit:

Omit<Client<T>, 'putRecord' | 'putRecords' | 'sink'>

Interfaces are the opposite - they give names to things for the TS compiler. This change uses this feature to provide more helpful names to Punchcard types:

// type reported now
Kinesis.Stream.ReadWrite<T>
// before
Omit<Client<T>, 'putRecord' | 'putRecords' | 'sink'>

Breaking Change: Moved the Firehose Validator construct under its own Construct.