8000 Extending the Function interface in the presence of an import statement · Issue #5944 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Extending the Function interface in the presence of an import statement #5944
Closed
@bgrieder

Description

@bgrieder

I would like to extend Function and this compiles fine

interface Function {
    hello(): any
}
Function.prototype.hello = function() {
    console.log('hello world')
}

function noop() {}

noop.hello() //==> 'hello world' in the console

However, as soon as I try to add an import statement, say

import { sayHello } from './Anything'

where Anything only contains

export function sayHello() { console.log('hello')}

The compilation fails on Function.protoype.hello with the message error TS2339: Property 'hello' does not exist on type 'Function'

Why ?

View in Playground

Note1: the compilation fails with tsc options set to either --target es5 --module commonjs or --target es6
Note2: my final goal is to export utilities in a library to be able to write code like myfunc.liftM(myMonad1, MyMonad2) or myfunc1.compose(myfunc2), etc...

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

      0