Implement BooleanWidget (#466)

* Implement BooleanWidget

* Merge function of addWidget

* Class conversion

* nit
This commit is contained in:
Chenlei Hu
2025-02-07 17:10:30 -05:00
committed by GitHub
parent 024ede680d
commit 75f067dbb3
6 changed files with 170 additions and 38 deletions

9
src/utils/type.ts Normal file
View File

@@ -0,0 +1,9 @@
/**
* Converts a plain object to a class instance if it is not already an instance of the class.
* @param cls The class to convert to
* @param obj The object to convert
* @returns The class instance
*/
export function toClass<P, C>(cls: new (plain: P) => C, obj: P | C): C {
return obj instanceof cls ? obj : new cls(obj as P)
}