Here is the vocabulary I am working with:
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>;
An error is occurring in the following code 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 attempting to create a vocabulary that allows me to specify arguments like "BatchSubmissionOptions" for a specific query to an internal server API. I want to define options as Post, Post with authentication headers, Get, or Get with authentication headers. The issue arises when trying to set properties after initialization.
Could there be a mistake in my definitions that I am overlooking?
EDIT: Following the recommendation of CodeQuiver, I have adjusted the code with more standardized separators based on the referenced article. Although sound advice, it did not fix the problem at hand.
Side note: While simplifying this problem for the question, I noticed that it doesn't flag an error when the value of "body" doesn't match MyBodyType, allowing different values. It only validates correctly when defining properties in MyBodyType; perhaps this is due to defining an object as {}?