Allow union and intersection types for SDC object properties, just like PHP does

Created on 7 March 2023, over 1 year ago
Updated 18 June 2024, 5 months ago

Problem/Motivation

Components allow two types of properties:
a) Arrays, which are declared and validated via JSONSchema
b) Objects, which are declared and validated via a Fully Qualified Class Name (FQN)

This is too restrictive, especially when typesafe objects are getting cheaper in PHP via readonly properties and constructor promotion, and union and intersection types are real today.

What this issue enables it sth like:

# The exact syntax was different, but you get it...
props:
  message: Drupal\mymodule\TextData | Drupal\mymodule\ImageData | null

with

final class TextData: {
  public __construct(public readonly string $text);
}
final class ImageData: {
  public __construct(public readonly string $src, public readonly string $alt);
}

Proposed resolution

Implement PHP types for all component properties.
Likely we can leverage code from tools like PHPStan.

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
single-directory componentsΒ  β†’

Last updated 3 days ago

Created by

πŸ‡©πŸ‡ͺGermany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024