<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSObjectConvertToTypeCallback",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:@T@JSObjectConvertToTypeCallback"
  },
  "title" : "JSObjectConvertToTypeCallback"
}
-->

# JSObjectConvertToTypeCallback

The callback type for converting an object to a particular JavaScript type.

```
typealias JSObjectConvertToTypeCallback = (JSContextRef?, JSObjectRef?, JSType, UnsafeMutablePointer<JSValueRef?>?) -> JSValueRef?
```

## Parameters

`ctx`

The execution context to use.

`object`

The [`JSObjectRef`](/documentation/JavaScriptCore/JSObjectRef) to convert.

`type`

A [`JSType`](/documentation/JavaScriptCore/JSType) that specifies the JavaScript type to convert to.

`exception`

A pointer to a [`JSValueRef`](/documentation/JavaScriptCore/JSValueRef) to return an exception in, if any.

## Return Value

The object’s converted value, or `NULL` if the object doesn’t convert.

## Discussion

If you name your function `ConvertToType`, you declare it like this:

```c
JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
```

If this function returns <doc://com.apple.documentation/documentation/Swift/false>, the conversion request forwards to the object’s parent class chain (which includes the default object class).

The system only invokes this function when converting an object to [`kJSTypeNumber`](/documentation/JavaScriptCore/kJSTypeNumber) or [`kJSTypeString`](/documentation/JavaScriptCore/kJSTypeString). An object that converts to [`kJSTypeBoolean`](/documentation/JavaScriptCore/kJSTypeBoolean) is `true`. An object that converts to [`kJSTypeObject`](/documentation/JavaScriptCore/kJSTypeObject) is itself.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)