Skip to content

specta: emit Feature.properties as TS unknown instead of recursive Value#7

Closed
johncarmack1984 wants to merge 1 commit into
mainfrom
john/specta-feature-properties-unknown
Closed

specta: emit Feature.properties as TS unknown instead of recursive Value#7
johncarmack1984 wants to merge 1 commit into
mainfrom
john/specta-feature-properties-unknown

Conversation

@johncarmack1984
Copy link
Copy Markdown
Collaborator

Summary

specta-rc.24's serde_json::Value Type impl is inline: true and recursive (Vec<Value>, Map<String, Value>). When inlined into a struct field like Feature.properties: Option<JsonObject>, the inlined arms reference an undefined Value name in the generated TS:

properties: { [key in string]:
    | "Null"
    | ({ Bool: boolean } & ...)
    | ({ Number: ... } & ...)
    | ({ String: string } & ...)
    | ({ Array: Value[] } & ...)         <- TS2304: Cannot find name 'Value'
    | ({ Object: Map<string, Value> } & ...)
};

Value is never emitted as a top-level alias because its NDT is inline: true, and requires_reference returns false for inline types -- so it's filtered out of the export pass. The inlined references are dangling.

Override the field at the TS layer to specta_typescript::Unknown (renders as TS unknown). Wire format and runtime behavior are unchanged; downstream consumers already have to walk properties opaquely since they're caller-defined per the GeoJSON spec.

Test plan

  • cargo build --features specta clean
  • cargo test --features specta (37 passed, 0 failed)

…Value

specta-rc.24's `serde_json::Value` Type impl is `inline: true` and
recursive (`Vec<Value>`, `Map<String, Value>`). When that gets
inlined into a struct field like `Feature.properties: Option<JsonObject>`,
the inlined arms reference an undefined `Value` name in the generated
TS, breaking typecheck downstream:

    properties: { [key in string]: ... | { Array: Value[] } & {...} | ... };
    //                                                ^^^^^ TS2304: Cannot find name 'Value'

Override the field at the TS layer to `specta_typescript::Unknown`
(renders as TS `unknown`). Wire format and runtime behavior are
unchanged; consumers already have to walk JSON properties opaquely
since they're caller-defined per spec.
@johncarmack1984
Copy link
Copy Markdown
Collaborator Author

Superseded by the named-JsonValue-alias approach on branch john/specta-json-value-alias (rev 2e34407). The Unknown override discarded structural type information; the new branch emits a proper recursive TS alias that consumers can narrow through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant