public protocol ConstructibleFromJSValue { associatedtype Constructed = Self static func construct(from value: JSValue) -> Constructed? } extension Optional: ConstructibleFromJSValue where Wrapped: ConstructibleFromJSValue { public static func construct(from value: JSValue) -> Wrapped.Constructed? { switch value { case .null, .undefined: return nil default: return Wrapped.construct(from: value) } } }