From 2e64489e9bf8e4307bc95b8d42d411eedc0832d0 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 18 Apr 2025 19:22:57 +0000 Subject: [PATCH] fix(directives): Add explicit type annotations to subscribeWithTemplate directive export --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/directives/classes.subscribewithtemplate.ts | 12 +++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 962cedb..fb0588c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-04-18 - 2.0.42 - fix(directives) +Add explicit type annotations to subscribeWithTemplate directive export + +- Imported DirectiveResult type for better typing +- Defined SubscribeWithTemplateFn signature to ensure proper type inference +- Used type assertion with 'as SubscribeWithTemplateFn' to improve type safety + ## 2025-04-18 - 2.0.41 - fix(directives) Refactor export statements in directives index for consistency diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index ac0b5c4..81441bd 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@design.estate/dees-element', - version: '2.0.41', + version: '2.0.42', description: 'A library for creating custom elements extending the lit element class with additional functionalities.' } diff --git a/ts/directives/classes.subscribewithtemplate.ts b/ts/directives/classes.subscribewithtemplate.ts index 7b1aa05..23a7a37 100644 --- a/ts/directives/classes.subscribewithtemplate.ts +++ b/ts/directives/classes.subscribewithtemplate.ts @@ -1,4 +1,5 @@ import { type TemplateResult, noChange } from 'lit'; +import type { DirectiveResult } from 'lit/directive.js'; import { AsyncDirective, directive } from 'lit/async-directive.js'; import { rxjs } from '@push.rocks/smartrx'; @@ -48,4 +49,13 @@ class SubscribeWithTemplateDirective extends AsyncDirective { * Directive that renders templates for each emission of an Observable. * Usage: html`${subscribeWithTemplate(myObservable, v => html`${v}`)}` */ -export const subscribeWithTemplate = directive(SubscribeWithTemplateDirective); \ No newline at end of file +/** + * Typed directive function signature: returns a Lit DirectiveResult. + */ +type SubscribeWithTemplateFn = ( + observable: rxjs.Observable, + templateFn: (value: T) => TemplateResult | unknown +) => DirectiveResult; +export const subscribeWithTemplate = directive( + SubscribeWithTemplateDirective +) as SubscribeWithTemplateFn; \ No newline at end of file