Skip to content

Emits undefined for unknown types in declaration file #7173

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

Closed
tjoskar opened this issue Feb 21, 2016 · 2 comments · Fixed by #7392
Closed

Emits undefined for unknown types in declaration file #7173

tjoskar opened this issue Feb 21, 2016 · 2 comments · Fixed by #7392
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@tjoskar
Copy link

tjoskar commented Feb 21, 2016

TypeScript Version:

1.7.5 / nightly (1.9.0-dev.20160221)

Code

Lets say I want to export some empty arrays:

// test.ts
export default {
  foo: [],
  bar: [],
  baz: []
}

and I want to generate a definition file for it:

> tsc test.ts --module commonjs -d

Expected behavior:

declare var _default: {
    foo: any[];
    bar: any[];
    baz: any[];
};
export default _default;

I expect the type to be any since the compiler don't know anything about the type.

Actual behavior:

declare var _default: {
    foo: undefined[];
    bar: undefined[];
    baz: undefined[];
};
export default _default;

Instead, I get undefined which is an invalid type (Error: can not find name 'undefined').

This seems like a bug?

Thanks and keep up the good work, I can't wait for version 2.0.

@Arnavion
Copy link
Contributor

Perhaps the same underlying cause as #6524

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 22, 2016
@DanielRosenwasser
Copy link
Member

It sounds like a default export should acquire the widened type of its RHS. The same issue exists for export = declarations.

export = {
    foo: []
}

@mhegazy mhegazy self-assigned this Feb 23, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Feb 23, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 4, 2016
@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

Successfully merging a pull request may close this issue.

5 participants