Skip to content

callable interface as parameter allows unknown properties #36826

@eps1lon

Description

@eps1lon

TypeScript Version: 3.9.0-dev.20200215

Search Terms: callable interface

Code

// callable interface
interface Accepted {
  (): void;
  foo: string;
}

function rejected() { }
rejected.foo = "";
rejected.bar = "";

function check(a: Accepted) { }

// desired: should reject unknown properties
// fail: accepts unknown properties
check(rejected);

concrete example

interface ForwardRefRenderFunction<T, P = {}> {
  (props: P, ref: Ref<T>): ReactElement | null;
  displayName?: string;
}

function forwardRef<T, P = {}>(render: ForwardRefRenderFunction<T, P>): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;

function Component() {
  return null;
}

Component.propTypes = {}

// should be rejected since `propTypes` aren't supported and add a runtime warning
forwardRef(Component);

Expected behavior:

  • unknown properties on functions are rejected

Actual behavior:

  • unknown properties are accepted

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions