Eric Liprandi
Eric Liprandi

Reputation: 5574

Why is TypeScript complaining that parameter has implicit type `any` when getCurrenUlr() returns a `Promise<string>`?

I am using protractor 4.x with TypeScript. Using TypeScript 2.0, the compiler complains in the following test:

it('should have url', done=>{
  browser.getCurrentUrl().then((x)=>{
    // do something with x
  })
})

It is saying: error TS7006: Parameter 'x' implicitly has an 'any' type. Yes, I know I can turn this off in the file, the tsconfig.json or explicitly set the typ, but my real question is why?

When I hover over browser.getCurrentUrl() it clearly says (property) Webdriver.getCurrentUrl: () => webdriver.promise.Promise<string> so, x should implicitly be of type string

Repro steps

tsconfig.json (straight from Protractor):

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": false,
        "declaration": false,
        "noImplicitAny": true,
        "outDir": "tmp",
        "types": ["node", "jasmine"]
    },
    "exclude": [
        "node_modules",
        "asyncAwait",
        "plugins.ts"
    ]
}

Upvotes: 3

Views: 1757

Answers (1)

James Monger
James Monger

Reputation: 10665

The reason for this is because you need to explicitly give a type to the parameter x:

it('should have url', done=>{
  browser.getCurrentUrl().then((x: string)=>{
    // do something with x
  })
})

Upvotes: 1

Related Questions