fix: validateLinkStart (#1430)

* fix validateLinkStart

* update comment

* use fallback

* cast to MaybeString

* update comment

Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com>

---------

Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com>
This commit is contained in:
Alex Christoffer Rasmussen
2025-01-06 13:12:03 +01:00
committed by GitHub
parent 891c43ba77
commit 743d7fa782
2 changed files with 8 additions and 4 deletions
@@ -2,12 +2,16 @@ import type { MaybeString } from 'ontime-types';
import { EndAction, TimerType, TimeStrategy } from 'ontime-types';
/**
* Check if a given value is a valid type of string, returns null otherwise
* Check if a given value is a valid type linkStart, returns the fallback otherwise
* linkStart can be a string (id of an event to link) or null (unlinked)
* @param {MaybeString} maybeLinkStart
* @returns {MaybeString}
*/
export function validateLinkStart(maybeLinkStart: unknown): MaybeString {
return typeof maybeLinkStart === 'string' ? maybeLinkStart : null;
export function validateLinkStart(maybeLinkStart: unknown, fallback: MaybeString = null): MaybeString {
if (typeof maybeLinkStart === 'string' || maybeLinkStart === null) {
return maybeLinkStart as MaybeString;
}
return fallback;
}
/**