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
@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
Most helpful comment
The fix should be in
typescript@nextlater tonight, and should be in2.9.2in two weeks.