TypeScript declarations for the HiGHS WebAssembly runtime. Initialization is asynchronous; model operations and solves are synchronous. Browser applications should run non-trivial solves in a Web Worker.
The default export loads and instantiates the highs.wasm binary. By default the loader fetches it from the same location as the JavaScript module, which works in Node.js and in browsers that serve the .wasm file alongside the loader.
Bundlers (webpack, Rollup, Vite, esbuild, etc.) do not always emit or resolve the .wasm asset automatically, and some rewrite asset URLs in ways that break the default lookup. When initialization fails with a fetch or compile error, pass InitOptions to the loader, with locateFile — return the correct URL for highs.wasm (a CDN, a versioned assets directory, an imported asset URL, etc.).
| Surface | Entry point | Use when |
|---|---|---|
| Legacy one-shot API | highs.solve() |
The model already exists as CPLEX LP text and no solver state must persist. |
| Persistent API | highs.createModel() / Model |
Building typed models, changing data, solving repeatedly, callbacks, basis access, ranging, IIS, or model I/O. Models own Wasm memory that garbage collection does not release; use withModel() or dispose(). |
| Raw API | highs.raw |
Native HiGHS status codes are required instead of exceptions. Inputs are still validated and copied. |
Search covers every exported method, property, type, constant, and enum. Start with Highs, Model, and ModelData.
This capacitated facility-location model chooses which facilities to open and routes customer demand through the open sites. It combines binary and continuous variables, named sparse model data, options, MIP callbacks, solve information, serialization, mutation, and repeated solves.
import loadHighs from "highs";
const highs = await loadHighs({ locateFile: (file) => `/assets/${file}` });
const { minimize } = highs.constants.objectiveSense;
const { continuous, integer } = highs.constants.variableType;
// x0..x1 open facilities; x2..x7 ship from two facilities to three customers.
const model = highs.createModel({
modelName: "facility-location",
numCols: 8,
numRows: 5,
sense: minimize,
colCost: [500, 300, 2, 4, 5, 3, 1, 3],
colLower: [0, 0, 0, 0, 0, 0, 0, 0],
colUpper: [1, 1, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity],
rowLower: [80, 60, 40, -Infinity, -Infinity],
rowUpper: [80, 60, 40, 0, 0],
integrality: [integer, integer, continuous, continuous, continuous, continuous, continuous, continuous],
colNames: ["open-north", "open-south", "n-a", "n-b", "n-c", "s-a", "s-b", "s-c"],
rowNames: ["demand-a", "demand-b", "demand-c", "north-capacity", "south-capacity"],
matrix: {
format: "csc",
numRows: 5,
numCols: 8,
starts: [0, 1, 2, 4, 6, 8, 10, 12, 14],
indices: [3, 4, 0, 3, 1, 3, 2, 3, 0, 4, 1, 4, 2, 4],
values: [-200, -200, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
},
});
try {
model.options.set({ output_flag: false, mip_rel_gap: 1e-4 });
const progress = [];
const firstRun = model.run({
[highs.constants.callbackType.mipLogging](event) {
progress.push({
nodes: event.data.mip_node_count,
gap: event.data.mip_gap,
});
return undefined;
},
});
const firstSolution = model.getSolution();
const firstPlan = Array.from(firstSolution.colValue, (value, index) => ({
variable: model.getColName(index),
value,
}));
console.log({
status: firstRun.modelStatus,
objective: model.getObjectiveValue(),
nodes: model.info.get("mip_node_count"),
dimensions: model.getDimensions(),
lp: model.exportModel("lp"),
progress,
firstPlan,
});
// Reuse the native model for a scenario where the south facility is cheaper.
model.changeColCost(1, 250);
const secondRun = model.run();
const secondSolution = model.getSolution();
console.log(secondRun.modelStatus, secondSolution.colValue);
} finally {
model.dispose();
}
| Feature | Reference | Detail |
|---|---|---|
| Typed model construction | ModelData |
Exact array dimensions, objective sense, names, integrality, and bounds are validated before native entry. |
| Sparse constraints | SparseMatrixInput |
starts, indices, and values use zero-based compressed sparse column storage. |
| Solver configuration | OptionStore.set() |
Option names are exact HiGHS snake_case names; the persistent wrapper rejects unsupported thread and path options. |
| Progress callbacks | HighsCallbackMap |
Callbacks run synchronously inside run(); callback controls expire when the handler returns. |
| Repeated scenarios | Model.changeColCost() |
Mutate the existing native model and solve again without rebuilding the sparse matrix. |
| Ownership | Highs.withModel() / Model.dispose() |
Persistent models own native memory that garbage collection does not release. Scoped, using, or finally disposal prevents Wasm leaks. |
ModelData, HessianInput, IndexSelectionModel.run(), Solution, ModelStatusCodeRangingResult, IisResult, BasisOptionStore, InfoStore, HighsConstantsRawRuntimeApi, RawModelApi