Skip to content

typescript enhancement for widget components#4345

Open
jsjames wants to merge 2 commits into
openhab:mainfrom
jsjames:create-guards
Open

typescript enhancement for widget components#4345
jsjames wants to merge 2 commits into
openhab:mainfrom
jsjames:create-guards

Conversation

@jsjames

@jsjames jsjames commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Dependent on #4340

Adds auto-generated type guards and conversions for components and component configs.

  • isConfig(config) is added as a type conversion function which can be used to validate and convert the type to a appropriate typescript config type.
  • isComponent(component, defaultConfig) can be used to validate a component is of the correct type and converts to the appropriate typescript component type and also the appropriate config type.

Example use:

import { OhCanvasLayer as OhCanvasLayerType, OhCanvasLayout as OhCanvasLayoutType, OhSvgElement } from '@/types/components/widgets'

...

// validate and layer will now be recognized as type OhCanvasLayerType.Component (and its config as OhCanvasLayerType.Config)
if (OhCanvasLayerType.isComponent(layer, {}))

...

const { config: rawConfig, childContext, slots } = useWidgetContext(context)

// config will now be validated and recognized as OhCanvasLayoutType.Config
const config = computed(() => {
  const raw = rawConfig.value
  if(OhCanvasLayoutType.isConfig(raw)) {
    return raw
  }

Custom config validation can also be added to generate-widget-component-ts.config.js

jsjames added 2 commits July 3, 2026 11:32
Signed-off-by: Jeff James <jeff@james-online.com>
Squashed commits:
[8a8e4df59] ready for review

Signed-off-by: Jeff James <jeff@james-online.com>
[628643ee4] WIP
Signed-off-by: Jeff James <jeff@james-online.com>
@jsjames jsjames requested review from florian-h05 and ghys as code owners July 4, 2026 16:26
@jsjames jsjames added awaiting other PR Depends on another PR enhancement New feature or request main ui Main UI labels Jul 4, 2026
@relativeci

relativeci Bot commented Jul 4, 2026

Copy link
Copy Markdown

#5976 Bundle Size — 13.88MiB (~+0.01%).

1152b35(current) vs 36efc97 main#5975(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 4 changes Improvement 1 improvement
                 Current
#5976
     Baseline
#5975
Improvement  Initial JS 1.47MiB(~-0.01%) 1.47MiB
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
Change  Chunks 844(+0.12%) 843
Change  Assets 983(+0.1%) 982
Change  Modules 2743(+0.04%) 2742
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 122 122
No change  Duplicate Packages 1 1
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#5976
     Baseline
#5975
Regression  JS 11.57MiB (~+0.01%) 11.57MiB
No change  CSS 906.49KiB 906.49KiB
No change  IMG 638.41KiB 638.41KiB
No change  Fonts 526.1KiB 526.1KiB
No change  Media 295.6KiB 295.6KiB
No change  Other 847B 847B

Bundle analysis reportBranch jsjames:create-guardsProject dashboard


Generated by RelativeCIDocumentationReport issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting other PR Depends on another PR enhancement New feature or request main ui Main UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant