Created
August 9, 2020 17:13
-
-
Save dontlaugh/8d702455f7320548926e9b2b9a14722b to your computer and use it in GitHub Desktop.
Abstract static getters w/o implementation?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Vpc { | |
static VpcAlias: string; | |
// Static getters require a default implementation, so we provide one | |
// that throws an error. This enforces our subclass overriding. | |
static get PublicSubnets(): string[] { Vpc.unimplemented("PublicSubnets"); return [""] }; | |
static get PrivateSubnets(): string[] { Vpc.unimplemented("PrivateSubnets"); return [""] }; | |
public static get Subnets(): string[] { | |
return [...Vpc.PublicSubnets, ...Vpc.PrivateSubnets]; | |
} | |
static unimplemented(method: string): void { | |
throw Error(`${Vpc.name} ${method} is not implemented`) | |
} | |
} | |
export class Dev1 extends Vpc { | |
// static readonly VpcAlias: "dev1" | |
static readonly VpcId = "vpc-0ced7da27751d4bd6" | |
static readonly SubnetPrivate1 = "subnet-01721256b852a87dc" | |
static readonly SubnetPrivate2 = "subnet-0267340547462a952" | |
static readonly SubnetPublic1 = "subnet-070313e525660c5c1" | |
static readonly SubnetPublic2 = "subnet-02ea690e1d6f92146" | |
public get PublicSubnets(): string[] { | |
return [Dev1.SubnetPublic1, Dev1.SubnetPublic2] | |
} | |
public get PrivateSubnets(): string[] { | |
return [Dev1.SubnetPrivate1, Dev1.SubnetPrivate2] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment