I have the following vocabulary:
type MyHeaders = {
Authorization: string;
Accept: "application/json";
};
type MyGetOptions = {
url: string;
json: true;
};
type MyOptionsWithHeaders = {
headers: MyHeaders;
};
type MyPostOptions<T> = MyGetOptions | {
body: T;
};
type MyPostOptionsWithHeaders<T> = MyPostOptions<T> | MyOptionsWithHeaders;
type MyBodyType = {};
type APICallOptions = MyPostOptionsWithHeaders<MyBodyType>;
The following code has an error under the "url" in "temp.url": "Property 'url' does not exist on type 'BatchSubmissionOptions'. Property 'url' does not exist on type 'OptionsWithHeaders'.ts(2339)"
const temp: APICallOptions = {
url: "url",
headers: {
Authorization: "Bearer token",
Accept: "application/json",
},
body: {
some: "stuff",
more_stuff: []
}
}
temp.url = "Hello"
I am trying to define a vocabulary that allows me to specify "BatchSubmissionOptions" as the arguments to a particular query to a particular API in an internal server. I want to be able to define something as a Post, or a Post with authentication headers, or a Get, or a Get with authentication headers. It allows me to set the "url" properly not the "temp" object, but it objects when I set the property after initialization.
Have I mis-defined something without knowing it?
EDIT: On the advice of CodeQuiver, I have updated the code with more standards-compliant separators according to the article he cited. While it is likely good advice, it did not resolve the problem.
Footnote: As I simplify this problem for this question, I'm also noticing that it isn't objecting to the fact that the value of "body" doesn't conform to MyBodyType, and it's allowing that; it correctly enforces things when I define properties in MyBodyType; maybe that's a feature of defining an object as {}?