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

Module not imported for meta-data references. #13449

Closed
mhegazy opened this issue Jan 12, 2017 · 3 comments
Closed

Module not imported for meta-data references. #13449

mhegazy opened this issue Jan 12, 2017 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Jan 12, 2017

From #12888 (comment)

after upgrading to TypeScript 2.1.5.
the issue regressed in different place.

when 'strictNullCheck' option is false the following typescript emitt invalid javascript code.

file: auxiliry.ts

export class SomeClass {
    field: string;
}

file: main.ts

import { SomeClass } from './auxiliry';

function annotation(): PropertyDecorator {
    return (target: any): void => { };
}

export class ClassA {
    @annotation() array: SomeClass | null;
}

Emitted code:

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
function annotation() {
    return function (target) { };
}
var ClassA = (function () {
    function ClassA() {
    }
    return ClassA;
}());
__decorate([
    annotation(),
    __metadata("design:type", auxiliry_1.SomeClass) // <-- auxiliry_1 is not emitted as require statement
], ClassA.prototype, "array", void 0);
exports.ClassA = ClassA;
@larrifax
Copy link

larrifax commented Mar 9, 2017

I'm having the same problem with strictNullChecks turned on.

@Input() employee: Employee | undefined; // This crashes at runtime
@Input() employee?: Employee; // Workaround

@Input() set employee(value: Employee | undefined) { // This crashes at runtime
    ...
}
@Input() set employee(value?: Employee) { // Compiler error
    ...
}

I can work around the problem on regular fields (line 1 & 2), but the workaround isn't applicable for properties as they don't allow optional parameters.

Will there be a bugfix for this in 2.2, or do I have to wait for 2.3? I'm currently stuck at 2.1 because of this problem.

@mhegazy mhegazy modified the milestones: TypeScript 2.3, Future Mar 24, 2017
@evmar
Copy link
Contributor

evmar commented Mar 29, 2017

Just wanted to note we have more than ten instances of this bug coming up within Google in various user code, which means we are needing to teach our users to sprinkle

const workaround = Import;

in their code to make some Import symbol not get dropped.

@studds
Copy link

studds commented May 3, 2017

When will this be released?

@mhegazy mhegazy modified the milestones: TypeScript 2.4, Future May 4, 2017
edcarroll added a commit to edcarroll/ng2-semantic-ui that referenced this issue Jul 3, 2017
@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
Projects
None yet
Development

No branches or pull requests

5 participants