Skip to content

Discrepancy inferring function parameter from context #1016

Closed
@benjaminjkraft

Description

@benjaminjkraft

As of today's nightly:

declare function compact<T>(array: T[]): T[];
declare function makeFooer(): Fooer;
interface Fooer {
  foo: (v: string) => string;
}
function f() {
  const _ = compact([makeFooer(), { foo: (v) => v }]);
}

This passes in TS, but fails in Go with:

src/compact.ts:7:43 - error TS7006: Parameter 'v' implicitly has an 'any' type.

7   const _ = compact([makeFooer(), { foo: (v) => v }]);

(Without the compact both TS and Go refuse to infer. With an explicit type on the const, they both infer successfully.)

This is simplified from a real issue with _.compact in our codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Type CheckingRelated to type checking, grammar checking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions