|
|
|
|
|
by PartiallyTyped
1204 days ago
|
|
Construct was not the correct word. The intention was to express that you do need to parse the object into something more specific that captures the properties that you require. Take for example APIGatewayProxyEvent [1], which has a property `queryStringParameters` with type: export interface APIGatewayProxyEventQueryStringParameters {
[name: string]: string | undefined;
}
You can then create a branded type like type AuthCodeEvent = APIGatewayProxyEvent & {
queryStringParameters: {
code: string;
state: string;
};
};
The branded type here means that as soon as you verify that the event has that structure above, and you can assume that it is correct in the code handles these specific cases.Though as the blog author mentioned in the other chain, the TS compiler is not particularly sound, so it's probably entirely possible to mess the structure and break the type without the compiler knowing about it. [1] https://github.com/DefinitelyTyped/DefinitelyTyped/blob/mast... |
|