Browse Source

Fix type check of unsupported language codes in Stripe checkout session

pull/8189/head
Thomas Kaul 2 days ago
parent
commit
62eaa0855e
  1. 8
      apps/api/src/app/subscription/subscription.service.ts
  2. 7
      apps/api/src/app/subscription/types/string-literal.type.ts

8
apps/api/src/app/subscription/subscription.service.ts

@ -23,8 +23,6 @@ import { addMilliseconds, isBefore } from 'date-fns';
import ms, { StringValue } from 'ms';
import Stripe from 'stripe';
import { StringLiteral } from './types/string-literal.type';
@Injectable()
export class SubscriptionService {
private readonly logger = new Logger(SubscriptionService.name);
@ -270,7 +268,11 @@ export class SubscriptionService {
const unsupportedLanguageCodes: Record<
Exclude<
(typeof SUPPORTED_LANGUAGE_CODES)[number],
StringLiteral<Stripe.Checkout.SessionCreateParams.Locale>
// Extract removes OtherString of Stripe, which matches every string
Extract<
Stripe.Checkout.SessionCreateParams.Locale,
(typeof SUPPORTED_LANGUAGE_CODES)[number]
>
>,
true
> = {

7
apps/api/src/app/subscription/types/string-literal.type.ts

@ -1,7 +0,0 @@
// Removes the open string type (e.g. OtherString of Stripe), which matches
// every string, and keeps only the string literals
export type StringLiteral<T> = T extends string
? string extends T
? never
: T
: never;
Loading…
Cancel
Save