reflect-metadata icon indicating copy to clipboard operation
reflect-metadata copied to clipboard

Overload signatures must all be ambient or non-ambient.

Open masonk opened this issue 7 years ago • 7 comments

On TS 2.1.4, when I import json-typescript-mapper": "^1.1.1", which depends on reflect-metadata,

I get many errors similar to this one:

node_modules/reflect-metadata/Reflect.ts(157,21): error TS2384: Overload signatures must all be ambient or non-ambient.

This is the same as issue #37, which is closed. It happens for targets es3, es5, and es6. It happens for the lowest supported version of reflect-metadata (0.1.3) and the most recent version (0.1.10).

I am not using Angular. This is basically a brand new project, with json-typescript-mapper and its reflect-metadata as the only deps.

I think the issue is that you've defined the es7 parts of Reflect as TypeScript, but there are already ambients for the es6 parts of Reflect in the core lib. One solution (which I haven't yet tried, but will soon), is to compile Reflect to .js and emit the types into .d.ts, where I hope they will merge with the core lib types.

Are you working on this project any more, or did it somehow get folded into core-js?

{	
	"compileOnSave": true,
    "compilerOptions": {
		"target": "es6",
        "module":"commonjs",
        "moduleResolution": "node", //to look up node_modules/@types/**
        // "target": "es6",
		// "module": "es6", // default
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
		"sourceMap": true,
        // "jsx": "react",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        // "strictNullChecks": true, // Off for json-typescript-mapper

        // This must be kept in sync with output.path and resolve.root
        // in dll.webpack.config and dll.webpack.config
		"outDir": "build",
        // "typeRoots" : ["typings", "@types"],
        "baseUrl": "src",
        "paths": {
            "*": [
                "*"
            ]
        }
	},
    "include": [
        "./**/*"
    ]
    //"exclude": [
        // "exclude" property defaults to excluding the 
        // node_modules, bower_components, and jspm_packages 
        // directories when not specified.
    //]
}

PS: Thanks for doing this. This is a neat proposal and I hope it makes it into es7.

masonk avatar Feb 27 '17 03:02 masonk

+1

aarondrabeck avatar Jul 10 '17 23:07 aarondrabeck

Hi @masonk,

Have you managed to find a solution after all?

leo-bo avatar Jul 11 '17 14:07 leo-bo

+1

markamccann avatar Jul 11 '17 15:07 markamccann

core-js has adopted their own implementation of this. I'm still working on the project, though its been low on my priority list as of late.

rbuckton avatar Jul 11 '17 16:07 rbuckton

@masonk, I think the issue is the following line in your tsconfig.json:

  "include": [
    "./**/*"
  ]

Setting "include" or "exclude" overrides the default behavior for both. As a result, the default "exclude" for node_modules is ignored. Either remove the "include" entry, or add an "exclude": ["node_modules", "bower_components", "jspm_packages"].

rbuckton avatar Jul 11 '17 17:07 rbuckton

I found this error with export declare function

http://www.typescriptlang.org/play/#src=namespace%20a%20%7B%0D%0A%20%20export%20namespace%20b%20%7B%0D%0A%20%20%20%20export%20declare%20function%20c()%3A%20void%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Anamespace%20a.b%20%7B%0D%0A%20%20export%20function%20c()%3A%20void%20%7B%0D%0A%20%20%20%20%2F%2F%20error%20%20%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0A%2F%2F%20example%202%0D%0A%0D%0Aexport%20namespace%20e%20%7B%0D%0A%20%20export%20namespace%20f%20%7B%0D%0A%20%20%20%20export%20declare%20function%20c()%3A%20void%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Aexport%20namespace%20e%20%7B%0D%0A%20%20export%20namespace%20f%20%7B%0D%0A%20%20%20%20export%20function%20c()%3A%20void%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20error%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%7D%0D%0A

or this example

// defs
namespace o {
  declare function e();
  declare function f();
  export declare function g();
}

// implements
namespace o {
  export function e() {
  }
  export function g() {
    // error overload ...
  }
}

// use
o.e(); // ok
o.f(); // error f must have export in declare
o.g(); // ok, if same file

WagnerExpansiva avatar Nov 14 '18 13:11 WagnerExpansiva

For my case it was a function called "print"!

soheilous avatar Feb 23 '23 07:02 soheilous