A typo in a message is found in game
The page and Lua agree on message names and shapes by convention. With a contract, every message is declared once, and
nui is typed from it: a wrong name, a missing key or a misspelt field is a type error.
Today
// The page sends a message. Nothing checks its name or its shape.fetch(`https://${GetParentResourceName()}/buyItem`, { method: 'POST', body: JSON.stringify({ item: 'water', ammount: 2 }),});RegisterNUICallback('buyItem', function(data, cb) -- data.amount is nil, and nobody is told. TriggerServerEvent('shop:buy', data.item, data.amount) cb({})end)Nothing fails until someone presses the button in game, and then nothing happens.
With Nexus UI
import { contract, s } from 'nexus/contract';export default contract({ calls: { 'shop:buy': { input: s.object({ item: s.string({ max: 40 }), amount: s.int({ min: 1, max: 100 }), }), output: s.object({ ok: s.boolean(), balance: s.int() }), rate: { limit: 5, per: 10 }, }, },});Found before the game starts, with the file, the line and the fix.
$ npx nexus checkerror web/screens/Shop.nexus:13:65: Object literal may only specify known properties, but 'ammount' does not exist in type '{ item: string; amount: number; }'. Did you mean to write 'amount'? (TS2561) 11 | 12 | async function buy() {> 13 | const result = await nui.call('shop:buy', { item: props.item, ammount: amount.value }); | ^ 14 | balance.value = result.balance; 15 | }error nexus check found 1 error.
nexus check reports type errors at their line in the .nexus file. In a
.ts module the editor shows them as you type. There is no language server for
.nexus files yet: see the roadmap.