Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'extends' is not compiling when used inside declaration file and importHelpers option is switched on #12724

Closed
Nipheris opened this issue Dec 7, 2016 · 19 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority

Comments

@Nipheris
Copy link

Nipheris commented Dec 7, 2016

TypeScript Version: 2.1.4 / 2.2.0-dev.20161207

Code

interface Animal {
	type: string;
}

export declare class Pet implements Animal {
	public type: string;
	public name: string;
	constructor();
}

export declare class Dog extends Pet {
	public breed: string;
	constructor();
}

Expected behavior:
Compiles successfully.

Actual behavior:
Compilation fails with the following error:

error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

The same source code compiles fine on TypeScript 2.1.1. Installed tslib package has version 1.2.0.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

are you using --importHelpers?

@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

never mind, saw the title :)

@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

The error should not be shown in the .d.ts file, this a bug.

but if you have tslib installed you should not see the error anyways, is this correct?

@mhegazy mhegazy added Bug A bug in TypeScript High Priority labels Dec 7, 2016
@timocov
Copy link
Contributor

timocov commented Dec 8, 2016

@mhegazy yeah, this is correct

@PavelPZ
Copy link

PavelPZ commented Dec 8, 2016

I cannot run importHelpers with installed tslib.

TypeScript Version: 2.1.4 vith VS.NET

Code
export const o = { a: 1, name: "o" };
export const copy = { ...o };

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "importHelpers": true,
    "lib": [
      "dom",
      "es6"
    ],
  }
}

installation
I use both JSPM and NPM

jspm install tslib
npm install tslib --save

package.json

{
  "jspm": {
    "dependencies": {
      "tslib": "npm:tslib@^1.2.0",
    }
  "dependencies": {
    "tslib": "^1.2.0"
  }
}

@mhegazy
Copy link
Contributor

mhegazy commented Dec 8, 2016

@PavelPZ, the compiler uses the same module resolution strategy to resolve tslib as it does with any other module. so you will need to either 1. add "moduleResolution": "node", or 2. add a path mapping for it: "paths": { "tslib" : ["./node_modules/tslib/tslib.d.ts"] }

@PavelPZ
Copy link

PavelPZ commented Dec 8, 2016

@mhegazy, thanks.

I am using JSPM, so I modified my tsconfig.json:

{
  "compilerOptions": {"baseUrl": ".",
     "paths": {
        "tslib": [ "jspm_packages/npm/tslib@1.2.0/tslib.d.ts" ]
     }, 

and compiler is now OK.

But there is a problem with runtime (Uncaught (in promise) Error: (SystemJS) tslib.__assign is not a function in Chrome).
tslib.js is correctly loaded, but its factory is never called.

jspm.config.js

SystemJS.config({
  paths: {
    "tslib": "jspm_packages/npm/tslib/tslib",

@mhegazy
Copy link
Contributor

mhegazy commented Dec 13, 2016

Fix for the original issue should be in tonight typescript@next.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 13, 2016

@PavelPZ i have not had time to look into the jspm issue yet. have you made progress past this issue, or are you still blocked on it?

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 13, 2016
@PavelPZ
Copy link

PavelPZ commented Dec 13, 2016

@mhegazy, no progress so far. I have no idea how to solve my observation tslib.js is correctly loaded, but its factory is never called. So e.g. tslib.__assign is undefined.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 13, 2016

Filed #12887 to track it.

@prencher
Copy link

prencher commented Dec 19, 2016

We are seeing this with 2.1.4 using Webpack 2 with awesome-typescript-loader. It only happens when using importHelpers: true. The above workaround using paths does not work:

ERROR in [at-loader] node_modules\@types\react\index.d.ts:186:31
    This syntax requires an imported helper but module 'tslib' cannot be found.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 19, 2016

This should be fixed in latest, can you give typescript@next a try?

@prencher
Copy link

prencher commented Dec 19, 2016

@mhegazy Just saw that in a related ticket. Just confirmed that It is indeed fixed in next, so we've just reverted the change for now. Thanks!

@schmuli
Copy link

schmuli commented Dec 27, 2016

@mhegazy I just tested this issue, using the latest version 2.2.0-dev.20161227, and I'm still seeing this error.

package.json:

{
  "name": "tslib-test",
  "version": "1.0.0",
  "dependencies": {
    "@angular/core": "^2.4.1",
    "tslib": "^1.4.0",
    "typescript": "2.2.0-dev.20161217",
    "rxjs": "^5.0.2",
    "zone.js": "0.7.4"
  }
}

tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "es6",
        "moduleResolution": "node",
        "noEmitHelpers": true,
        "importHelpers": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "lib": ["es6", "dom"]
    }
}

main.ts:

import { NgModule } from '@angular/core';

@NgModule({

})
export class MyModule {

}

Error in Console:

$ node_modules/typescript/bin/tsc -p .
node_modules/@angular/core/src/metadata/di.d.ts(178,48): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 28, 2016

thanks @schmuli for the repro, fix up in https://github.com/Microsoft/TypeScript/pull/13189/files

@Delagen
Copy link

Delagen commented Mar 2, 2017

When it will be published? in 2.2.1 is the same

@mhegazy
Copy link
Contributor

mhegazy commented Mar 2, 2017

@Delagen we believe the issue should be fixed in TS 2.2.1, if you are still seeing it please file a new issue and give us some information to reproduce the issue locally.

@ckotzbauer
Copy link

Created new issue for 2.2.1: #14468

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority
Projects
None yet
Development

No branches or pull requests

9 participants