Skip to content

Overriding interface/types definitions to make properties required or optional #36286

@Vadorequest

Description

@Vadorequest

Similar to #3402

I use this base type for all my DB models:

export declare type GraphCMSSystemFields = {
  id: string; // ID is required (I want it to be required by default, as it's the most common use case)
  createdAt?: string;
  status?: string;
  updatedAt?: string;
  __typename?: string;
}

But then I have a few exceptions:

import { GraphCMSSystemFields } from './GraphCMSSystemFields';

export declare type AssetTransformations = {
  id?: string; // Attempt to override the ID "required/optional" by using `?`
  height?: number;
  width?: number;
} & GraphCMSSystemFields;

I have no way of making the id optional if I make it required in the base type. Similarly, if I make it optional in the base type, I have no way to enforce it as being required on some sub types.

Isn't that a use-case that should be considered in the spec?
Also, there is no warning at all when doing this, it just silently doesn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions