From aa8dc1919f13a37e7fdb0242a3f641877797fe79 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Wed, 5 Jun 2024 23:22:00 +0200 Subject: [PATCH] Make getKcContext mock return type less narrow --- src/account/KcContext/getKcContextMock.ts | 4 +++- src/login/KcContext/getKcContextMock.ts | 4 +++- test/login/KcContext.typelevel-spec.ts | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/account/KcContext/getKcContextMock.ts b/src/account/KcContext/getKcContextMock.ts index 0735bb81..3adf0688 100644 --- a/src/account/KcContext/getKcContextMock.ts +++ b/src/account/KcContext/getKcContextMock.ts @@ -47,7 +47,9 @@ export function createGetKcContextMock< >(params: { pageId: PageId; overrides?: DeepPartial>; - }): Extract { + // NOTE: We choose to have a return type less precise than Extract { + // because we want to be able to use the mock just as the real KcContext. + }): KcContext { const { pageId, overrides } = params; const kcContextMock = structuredCloneButFunctions( diff --git a/src/login/KcContext/getKcContextMock.ts b/src/login/KcContext/getKcContextMock.ts index 23b32d03..b1e8322a 100644 --- a/src/login/KcContext/getKcContextMock.ts +++ b/src/login/KcContext/getKcContextMock.ts @@ -47,7 +47,9 @@ export function createGetKcContextMock< >(params: { pageId: PageId; overrides?: DeepPartial>; - }): Extract { + // NOTE: We choose to have a return type less precise than Extract { + // because we want to be able to use the mock just as the real KcContext. + }): KcContext { const { pageId, overrides } = params; const kcContextMock = structuredCloneButFunctions( diff --git a/test/login/KcContext.typelevel-spec.ts b/test/login/KcContext.typelevel-spec.ts index d418a127..9404085f 100644 --- a/test/login/KcContext.typelevel-spec.ts +++ b/test/login/KcContext.typelevel-spec.ts @@ -64,7 +64,7 @@ import { Reflect } from "tsafe/Reflect"; pageId: "login.ftl" }); - type Expected = Extract; + type Expected = KcContext; assert>(); } @@ -74,7 +74,7 @@ import { Reflect } from "tsafe/Reflect"; pageId: "register.ftl" }); - type Expected = Extract; + type Expected = KcContext; assert>(); } @@ -84,7 +84,7 @@ import { Reflect } from "tsafe/Reflect"; pageId: "my-custom-page.ftl" }); - type Expected = Extract; + type Expected = KcContext; assert>(); } @@ -181,7 +181,7 @@ import { Reflect } from "tsafe/Reflect"; pageId: "login.ftl" }); - type Expected = Extract; + type Expected = KcContext; assert>(); } @@ -191,7 +191,7 @@ import { Reflect } from "tsafe/Reflect"; pageId: "register.ftl" }); - type Expected = Extract; + type Expected = KcContext; assert>(); }