Typescript: export { default } from broken in 2.9

Created on 31 May 2018  路  6Comments  路  Source: microsoft/TypeScript

TypeScript Version: 2.9.1 (also tried 3.0.0-dev.20180531)

Search Terms: export default, export default from

Code

A project that was working on 2.8 started failing on 2.9 with this error:

.../dts/Schema.d.ts:6:46 - error TS2507: Type 'typeof import(".../node_modules/shapeshifter/...' is not a constructor function type.

export default class Schema<T = any> extends BaseSchema {

The shapeshifter declaration looks like the following.

export { default } from './Schema';
export { MetadataField, PrimaryKey, Relation } from './types';

The above causes the error, while the following does not cause the error.

import Schema from './Schema';
export { MetadataField, PrimaryKey, Relation } from './types';
export default Schema;

Expected behavior:

It doesn't error and supports export { default } from.

Actual behavior:

It errors.

Related Issues: N/A

Bug Fixed

Most helpful comment

The fix should be in typescript@next later tonight, and should be in 2.9.2 in two weeks.

All 6 comments

@milesj can you share more information please. can you share the project or a sample?

Can't show the project as it's an internal employer project.

However, shapeshifter is public (built with TS 2.8). The index export is here: https://github.com/milesj/shapeshifter/blob/master/src/index.ts#L6

And all the consuming project is doing is:

import BaseSchema from 'shapeshifter';

export default class Schema extends BaseSchema {}

Which triggers the error in 2.9.

An example of a declaration file that can no longer be imported in TS 2.9:

// show-error.hbs.d.ts
export interface Context {
  fails: ('file_type'|'file_size'|'total_file_size')[]
}
const _: HandlebarsTemplateDelegate<Context>
export { _ as default }

import showError from './show-error.hbs'; showError({ fails: [] }) throws an error saying that showError is not callable. It seems to be treated as if it was a namespace import (import * as showError from).

However, import { default as showError } from './show-error.hbs' does produce a callable showError.

Thanks for the quick fix!

The fix should be in typescript@next later tonight, and should be in 2.9.2 in two weeks.

I have a similar bug with 2.9.2 #24988

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wmaurer picture wmaurer  路  3Comments

dlaberge picture dlaberge  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

uber5001 picture uber5001  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments