{"record":{"id":"c95725afb10637af","repo":"slint-ui/slint","slug":"write-typescript-generated-language-ts","errorCode":null,"errorMessage":"write typescript/generated/language.ts","messagePattern":"write typescript/generated/language\\.ts","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/node/build.rs","lineNumber":202,"sourceCode":"        for (field, rust_ty, field_docs, _) in &s.fields {\n            write_jsdoc(&mut ts, \"        \", field_docs);\n            ts.push_str(&format!(\n                \"        {field}: {ts_ty};\\n\",\n                ts_ty = map_field_type(rust_ty, &in_language),\n            ));\n        }\n        ts.push_str(\"    };\\n\");\n    }\n    ts.push_str(\"}\\n\");\n\n    let out_dir = PathBuf::from(env!(\"CARGO_MANIFEST_DIR\")).join(\"typescript\").join(\"generated\");\n    std::fs::create_dir_all(&out_dir).expect(\"create typescript/generated directory\");\n    let out_path = out_dir.join(\"language.ts\");\n    // Only write if the content actually changed, so we don't invalidate downstream builds.\n    let need_write =\n        std::fs::read_to_string(&out_path).map(|existing| existing != ts).unwrap_or(true);\n    if need_write {\n        std::fs::write(&out_path, ts).expect(\"write typescript/generated/language.ts\");\n    }\n}\n\n/// Map a Rust field type (as stringified by the macro) to the TS type used in the generated\n/// language module. Fails the build with a clear message when a new struct adds an unmapped\n/// type — better than silently emitting `unknown`.\nfn map_field_type(rust_ty: &str, in_language: &HashSet<&'static str>) -> String {\n    let t = rust_ty.trim();\n    match t {\n        \"bool\" => \"boolean\".to_string(),\n        \"i32\" | \"f32\" | \"f64\" | \"Coord\" => \"number\".to_string(),\n        \"SharedString\" => \"string\".to_string(),\n        // Types exposed by the binding outside the `language` namespace.\n        \"DataTransfer\" => \"DataTransfer\".to_string(),\n        \"LogicalPosition\" => \"{ x: number; y: number }\".to_string(),\n        ident if in_language.contains(ident) => ident.to_string(),\n        other => panic!(\n            \"Unmapped struct field type `{other}` in for_each_builtin_structs!. \\","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/slint-ui/slint/blob/3fd8f2ec03c2aa8a95d5f4b9daa299c7b8bf4016/api/node/build.rs#L184-L220","documentation":"Error \"write typescript/generated/language.ts\" thrown in slint-ui/slint.","triggerScenarios":"Thrown at api/node/build.rs:202 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the build script can write typescript/generated/language.ts.","Check disk space and file permissions."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3fd8f2ec03c2aa8a95d5f4b9daa299c7b8bf4016","analyzedAt":"2026-08-19T23:23:16.610Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}