types (breaking): narrow TermWrapper's Literal/Quad member surface; remove IRdfJsTerm#86
Draft
jeswr wants to merge 1 commit into
Draft
types (breaking): narrow TermWrapper's Literal/Quad member surface; remove IRdfJsTerm#86jeswr wants to merge 1 commit into
jeswr wants to merge 1 commit into
Conversation
Removes the Literal members (language, direction, datatype) and the Quad members (subject, predicate, object, graph) from TermWrapper's declared type and deletes the IRdfJsTerm interface. The members remain available at runtime through prototype-defined getters that delegate to the wrapped term, so runtime behaviour is unchanged. A new optional type parameter narrows termType to that of the wrapped term. BREAKING CHANGE: reading a term-type-specific member such as language or datatype off a wrapper now requires narrowing to the term type that declares it (e.g. a cast to Literal). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 6, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
TermWrappercurrently declares every member of every RDF/JS term type, solanguage,datatype,direction,subject,predicate,objectandgraphappear to exist on every wrapper — including wrappers of term types that do not have them. As raised in the #61 discussion, these are false types:languageis declared to be defined even on a wrappedNamedNode, where it isundefinedat runtime.This PR narrows the declared type surface to the members common to all term types (
termType,value,equals):src/type/IRdfJsTerm.ts(internal, never exported frommod.ts).Literal/Quadgetters from the class body and re-defines them onTermWrapper.prototypevia anObject.definePropertyloop. Runtime behaviour is unchanged (same delegation to the wrapped term, same non-enumerable configurable accessors); they simply no longer appear in the declared type or the emitted.d.ts.TermWrapper<T extends Term = Term>that narrowstermTypeto that of the wrapped term (e.g.TermWrapper<Literal>hastermType: "Literal").ensureDatatype/ensureListRootandTermFrom.instancenow takeTermWrapper;ensure.tsandLiteralAs.tscast toLiteralinternally where they readlanguage/datatype.test/unit/term_wrapper_term_members.test.tscovers runtime delegation of all seven members (literal, quad, subclass, and absent-member cases) and guards the type surface with@ts-expect-errorassertions and atermTypenarrowing check.BREAKING
Consumer code that reads a term-type-specific member off a wrapper (e.g.
wrapper.language) no longer type-checks. Narrow to the term type that declares it (e.g.(wrapper as unknown as Literal).language), or — once #83 lands — hold the intersection type returned byTermWrapper.from, which exposes these members on theLiteral/Quadside of the intersection without casts. Runtime behaviour is unchanged.Relationship to #74, #83 and #61
IRdfJsTermdeletion, the prototype-defined getters, and theensure.ts/TermFrom.tsfallout. The other slice of wip/term wrapper type #74 (thefromstatic factory) is superseded by feat: TermWrapper.from static factory with intersection return type #83; together the two cover all of wip/term wrapper type #74.from's intersection return type is what makes the narrowed surface ergonomic to consume.TermWrapper#fromandTermWrapper#in#61 review thread.Given the ongoing type-direction discussion on #61/#74, this is deliberately a draft and should not merge before that discussion resolves.