-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
breakingBreaking change that requires a major version bump.Breaking change that requires a major version bump.on holdItem is on hold, pending a new release or milestone.Item is on hold, pending a new release or milestone.
Milestone
Description
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
Tparameter onAction<T>is effectively advisory rather than enforced. - Callers can persist settings with a completely different object shape than
T. getSettingsallows 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
Labels
breakingBreaking change that requires a major version bump.Breaking change that requires a major version bump.on holdItem is on hold, pending a new release or milestone.Item is on hold, pending a new release or milestone.