Browse Source

Fix type check of unsupported language codes in Stripe checkout session

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

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

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

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

@ -0,0 +1,7 @@
// 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