Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Functions with overloads don't automatically get types for their parameters #32037

Copy link
Copy link
@fregante

Description

@fregante
Issue body actions

TypeScript Version: 3.5.2

Search Terms:

noImplicitAny true
overloaded
inferred types

Code

I don't know the exact terms for what's happening in the first example. Are these parameters' "types being inferred"?

// `text` has type `string`
window.alert = (text) => {
	return window.alert(text);
}

// Both parameters are `any`, because `addEventListener` has overloads
window.addEventListener = (type, fn) => {
	return window.addEventListener(type, fn);
}

Expected behavior:
They should follow these types from lib.dom.d.ts:

addEventListener<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;

Actual behavior:

Parameter 'type' implicitly has an 'any' type. ts(7006)
Parameter 'fn' implicitly has an 'any' type. ts(7006)

Playground Link: https://www.typescriptlang.org/play/#src=window.alert%20%3D%20(text)%20%3D%3E%20%7B%0D%0A%09return%20window.alert(text)%3B%0D%0A%7D%0D%0A%0D%0Awindow.addEventListener%20%3D%20(type%2C%20fn)%20%3D%3E%20%7B%0D%0A%09return%20window.addEventListener(type%2C%20fn)%3B%0D%0A%7D

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.