#NestJS HttpException as a TypeScript class?

3 messages · Page 1 of 1 (latest)

hidden dagger
#

I need a more advanced HttpException feature than NestJS provides. So, I'm rewrite it to TypeScript separate class because I would like it to function the same way but be more extensive, universal, and tailored to my needs.

#

My Code:

export interface HttpExceptionOptions {
    cause?: unknown;
    description?: string;
}
static getDescriptionFrom(descriptionOrOptions: string | HttpExceptionOptions): string {
        return isString(descriptionOrOptions)
            ? descriptionOrOptions
            : descriptionOrOptions?.description;
    }

Error:
Type 'string | undefined' cannot be assigned to type 'string'.
Type 'undefined' cannot be assigned to type 'string'. ts(2322)

#

And I wonder what I'm doing wrong, it should be compatible with the original types and the original version of the function, right?