-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make "Reference" type generic? #70
Comments
I like the idea, but I am struggling with what the output should look like. In However, the datatype Reference doesn't contain an object - it just has an optional Is the goal that |
Yup, exactly.
..with the general pattern repeated for other resource types to match more closely with the FHIR specification and be more directly implementable without casting madness. |
Updating here for visibility. @jmandel suggested the following:
Which, I believe is in line with what we are looking for (e.g., the |
From the string PR, this is a bit stricter (edit: tho I'm not sure is valid TS lol)
Although I suppose if you have T that is accessing ["resourceType"] you're probably okay already. Or did you mean something else by the undefined case @GinoCanessa ? |
It would be nice to check interface Reference<T extends Resource> {
...
reference?: `${T["resourceType"]}/\s+`,
...
} Now it is not possible because microsoft/TypeScript#41160 has to be approved first. Regarding defining the interface Reference<T extends Resource> {
...
type?: `${T["resourceType"]}`,
...
} However, based on type definition https://www.hl7.org/fhir/references-definitions.html#Reference.type the valueset binding for interface Reference<ResourceType extends (FhirResourceType | string) = FhirResourceType> {
...
type: ResourceType;
...
};
let r1:Reference<"Patient">;
let r2:Reference<"AnotherValue">; I don't this. I would like to hear your thoughts. |
Yes, this would be great @ir4y! I am looking forward to microsoft/TypeScript#41160, but wonder how we could do this to be somewhat backward compatiable? |
Would it be possible to make the TypeScript version of Reference generic? It is very difficult to enforce constraints without this, and TypeScript supports complex "A | B | C | D"-style generics.
We are trying to strictly enforce all manner of constraints in our information models for both IG publishing and software development purposes, and such refinements would be very welcome!
The text was updated successfully, but these errors were encountered: