fix: incorrect TypeScript type for getPayload() props, throw proper error if config doesn't exist

This commit is contained in:
Alessio Gravili
2024-03-10 14:14:29 -04:00
parent 5f76097562
commit e746f17167
2 changed files with 13 additions and 1 deletions

View File

@@ -12,6 +12,10 @@ if (!cached) {
}
export const getPayload = async (options: InitOptions): Promise<Payload> => {
if (!options?.config) {
throw new Error('Error: the payload config is required for getPayload to work.')
}
if (cached.payload) {
const config = await options.config

View File

@@ -298,6 +298,10 @@ export class BasePayload<TGeneratedTypes extends GeneratedTypes> {
* @param options
*/
async init(options: InitOptions): Promise<Payload> {
if (!options?.config) {
throw new Error('Error: the payload config is required to initialize payload.')
}
this.logger = Logger('payload', options.loggerOptions, options.loggerDestination)
this.config = await options.config
@@ -420,7 +424,11 @@ if (!cached) {
cached = global._payload = { payload: null, promise: null }
}
export const getPayload = async (options?: InitOptions): Promise<BasePayload<GeneratedTypes>> => {
export const getPayload = async (options: InitOptions): Promise<BasePayload<GeneratedTypes>> => {
if (!options?.config) {
throw new Error('Error: the payload config is required for getPayload to work.')
}
if (cached.payload) {
return cached.payload
}