-
Notifications
You must be signed in to change notification settings - Fork 164
refactor!: use a union type for SignatureType #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,22 @@ | |
// executing the client function. | ||
export const FUNCTION_STATUS_HEADER_FIELD = 'X-Google-Status'; | ||
|
||
export enum SignatureType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree with using string literals and arrays instead of enums. Enums provide benefits over literal values such as better typing, autocompletion, and less code here. We don't plan an arbitrary signature type until the FF contract changes. This is also a breaking change to the API, not an internal refactor. Could we discuss a bit more about the tradeoff in the PR / an issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're fine changing to the union types, but we shouldn't completely remove the enum as it's an exported interface, unless we have strong reason to introduce a breaking change. For example, we had a customer complaint about a similar small interface change: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we give customer an opportunity to pass the value to use in any meaningful way (the signature type can only be provided as an env var or cli flag), so I don't think we should be too concerned about changing this. I see your point about why this is breaking change now. I will updated the conventional commit tag. |
||
HTTP = 'http', | ||
EVENT = 'event', | ||
CLOUDEVENT = 'cloudevent', | ||
} | ||
/** | ||
* List of function signature types that are supported by the framework. | ||
*/ | ||
export const SignatureType = ['http', 'event', 'cloudevent'] as const; | ||
|
||
/** | ||
* Union type of all valid function SignatureType values. | ||
*/ | ||
export type SignatureType = typeof SignatureType[number]; | ||
|
||
/** | ||
* Type guard to test if a provided value is valid SignatureType | ||
* @param x the value to test | ||
* @returns true if the provided value is a valid SignatureType | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const isValidSignatureType = (x: any): x is SignatureType => { | ||
return SignatureType.includes(x); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing TS error for misconfigured strings with all.
For example, if I type:
here, I won't get a TS error. I'd rather just be able to type
NodeEnv.
and see an autocompleted result of options and errors if I mistype.