Skip to content

[Bug]: GetLine returns raw number for NominalValue but types declare IfcValue #1739

@cassus

Description

@cassus

What happened?

GetLine() returns a raw JavaScript number for IfcPropertySingleValue.NominalValue, but TypeScript types declare IfcValue | null.

TypeScript types (web-ifc-api.d.ts):

NominalValue: IfcValue | null
// where IfcValue = IfcMeasureValue | IfcSimpleValue | IfcDerivedMeasureValue

Runtime behavior:

typeof readProp.NominalValue === "number"  // true
readProp.NominalValue instanceof IFC4X3.IfcInteger  // false
readProp.NominalValue  // 7 (raw number, not wrapper)

This mismatch causes TypeScript code to fail at runtime when pattern matching on IfcValue types.

String types (IfcText, IfcLabel) and booleans (IfcBoolean) retain their wrappers - only numeric types return raw primitives.

Minimal reproduction

import { IFC4X3, IfcAPI } from "web-ifc"

const api = new IfcAPI()
await api.Init()
const modelID = api.CreateModel({ schema: "IFC4X3" })

// Create property with IfcInteger value
const prop = new IFC4X3.IfcPropertySingleValue(
  new IFC4X3.IfcIdentifier("TestProperty"),
  null,
  new IFC4X3.IfcInteger(7),
  null
)

// Before write: proper wrapper
console.log(prop.NominalValue instanceof IFC4X3.IfcInteger) // true
console.log((prop.NominalValue as IFC4X3.IfcInteger).value) // 7

// Write to model
api.WriteLine(modelID, prop)

// Read back
const readProp = api.GetLine(modelID, prop.expressID) as IFC4X3.IfcPropertySingleValue

// After read: raw number instead of wrapper
console.log(readProp.NominalValue instanceof IFC4X3.IfcInteger) // false ❌
console.log(typeof readProp.NominalValue) // "number"
console.log(readProp.NominalValue) // 7 (value preserved, type lost)

api.CloseModel(modelID)

This causes issues because TypeScript types declare NominalValue as IfcValue | null, but runtime returns raw primitives for numeric types.

Version

0.0.72

What browsers are you seeing the problem on?

None (Node.js environment)

Anything else?

Related to #1561 but different symptom:

The type definitions in web-ifc-api.d.ts declare NominalValue as IfcValue | null which doesn't include raw primitives, causing type mismatches at runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions