Skip to content

getSettings/setSettings in Action<T> allow unrelated types #133

@fhollermayer

Description

@fhollermayer

Description

In Action<T extends JsonObject>, both getSettings and setSettings introduce their own generic type parameter U extends JsonObject = T.

Because U is not constrained by T (only defaults to it), callers can explicitly supply any U extends JsonObject and bypass the Action<T> type entirely. As a result, Action<T> does not actually enforce the shape of the settings it is supposed to represent.

In addition, setSettings will infer U from the argument passed, so even without explicitly providing a generic parameter, it still accepts settings objects unrelated to T.

Examples

type MySettings = {a: 42};

class Demo extends SingletonAction<MySettings> {
  override async onWillAppear(ev: WillAppearEvent<MySettings>): Promise<void> {
  
    await ev.action.setSettings({b: ""});
    
    (await ev.action.getSettings()).a.toFixed(); // crash
  }
}

Impact

  • The T parameter on Action<T> is effectively advisory rather than enforced.
  • Callers can persist settings with a completely different object shape than T.
  • getSettings allows consumers to “assert” any return type, even if it does not match the runtime payload.
  • This weakens type safety and makes refactors and schema changes more error-prone.

Suggested fix

setSettings(): Promise<T> and setSettings(settings: T): Promise<void>

I supply this as an issue rather than a pull request because it might break the current API for some devs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingBreaking change that requires a major version bump.on holdItem is on hold, pending a new release or milestone.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions