-
Notifications
You must be signed in to change notification settings - Fork 45
httpMethod no longer expects a string in TypeScript #331
Comments
@shruggr thanks for the bug report; @xiaozhenliu-gg5, @alexander-fenster looks like potentially a bug with the move to the microgenerator? |
@shruggr Yeah, we're aware of this problem. If you had used JavaScript, the Right now, there are two ways to solve it:
import * as protos from '@google-cloud/tasks/build/protos/protos';
const task = {
httpRequest: {
httpMethod: protos.google.cloud.tasks.v2.HttpMethod.POST,
. . .
};
import * as protos from '@google-cloud/tasks/build/protos/protos';
const task = protos.google.cloud.tasks.v2.Task.fromObject({
httpRequest: {
httpMethod: 'POST',
. . .
}); I have submitted an issue for the code generator we use, we'll figure out the best way to make it transparent, but until that time, feel free to use one of the above solutions. |
This should be fixed in v1.7.3. We updated the types to include all possible string values using |
I still have this issue in v1.9.0 |
@jacksontong All
If you still see the error, could you please share your code here? Thank you! |
@alexander-fenster here is the code https://codesandbox.io/s/cranky-taussig-q5j2q |
I ran into this issue and was able to just reference the
With code:
I'm on version 2.0.0 of |
I ran into the same issue today using v2.1.0. My code (copied from the js sample): const task = {
httpRequest: {
httpMethod: 'POST',
url,
},
}
const request = { parent, task }
const [response] = await client.createTask(request) Error:
Using this code worked for me: import { CloudTasksClient, protos } from '@google-cloud/tasks'
const task = {
httpRequest: {
httpMethod: protos.google.cloud.tasks.v2.HttpMethod.POST,
url,
},
} |
OK, I see the problem now. The auto-inferred type for I guess you could make the sample work by writing |
I also ran into this issue recently, has this been fixed or does it need to be reopened? Maybe exposing the |
We had the same issue in 2.3.2. @alexander-fenster's solution to use What ended up working for us was explicitly typing the |
Still an issue as of The basic 'Getting Started' won't work with TS without directly importing the |
Just bumped into this today with |
Why is this issue closed? It is not clear that we need to use |
@MorenoMdz It should accept a string enum value. The type definition uses |
We are using version 3.0.0, this works: const task = {
httpRequest: {
httpMethod: protos.google.cloud.tasks.v2.HttpMethod.POST,
url: functionUrl,
oidcToken: {
serviceAccountEmail,
audience: new URL(functionUrl).origin
},
headers: {
"Content-Type": "application/json",
...headers
},
body
},
scheduleTime: { seconds: targetTimeInSeconds }
}; But |
This is not the library problem, but the problem with how TypeScript guesses the type of the You can do the following to tell TypeScript compiler that the type of the import {CloudTasksClient, protos} from '@google-cloud/tasks';
...
const task: protos.google.cloud.tasks.v2.ITask = {
appEngineHttpRequest: {
httpMethod: 'POST',
relativeUri: '/log_payload',
},
}; and then it will understand that Since our samples are in JavaScript and not in TypeScript, sometimes (in cases like this one) they cannot be easily copy-pasted to the TypeScript code. I took I hope that helps! |
In 1.7.0, when creating a new task, I get the following error. It works fine in 1.6.0
Environment details
@google-cloud/tasks
version: 1.7.0Steps to reproduce
The text was updated successfully, but these errors were encountered: