-
Notifications
You must be signed in to change notification settings - Fork 253
Description
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 | IfcDerivedMeasureValueRuntime 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:
- [Bug]: The type of the NominalValue parameter in the IfcPropertySingleValue attribute is lost when read using the GetLine method. #1561:
NominalValuebecomesnull(data loss) - This issue:
NominalValueis7(value preserved, type wrapper lost)
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.