Working on react application in TypeScript.
I'm trying to understand the correct syntax for exporting a default component using as
Up till now I've used:
class HomePage extends Component<IProps, IState> {
...
}
export default HomePage
or in shortly:
export default class HomePage extends Component<IProps, IState> {
...
}
now, after adding redux support. I have something like:
class HomePage extends Component<IProps, IState> {
...
}
const mapStateToProps = (state: StoreState) => {
...
};
const mapDispatchToProps = {
...
};
export default connect(mapStateToProps, mapDispatchToProps)(HomePage);
but I can't figure it out how to add as to the connect default export
e.g something like:
// This is NOT working. I get Syntax error.
export default connect(mapStateToProps, mapDispatchToProps)(HomePage) as HomePage;
is it possible? or should I do it? it's seems that anyway the export name is HomePage (when I'm importing HomePage in other file, the IDE is automatically detects and import this file). Where is it taken from? the name of the file (HomePage.tsx)?
This is do work for me:
const connectedHomePage = connect(mapStateToProps, mapDispatchToProps)(HomePage)
export {connectedHomePage as HomePage};
but it's two lines (I prefer in one line) and it's not a default export.
so, is there a way to export default AND adding as to the statement? just so it will be clear what is the exported name?


export defaultalways exports as, well,default. What are you expecting to get with this syntax?HomePageand will be able to auto-import it (which it actually does!) I understood why IDE can recognizeexport default class HomePageas HomePage (import HomePage from './HomePage') but wasn't sure how it can also work forexport default connect(mapStateToProps, mapDispatchToProps)(HomePage);when I write in another fileHomePagethe IDE can find it and auto import it the same. so I guess maybe it's know which default I want to import by the filename?export default ..and not e.g.export const HomePage = ...?import HomePage from './HomePage'looks better thanimport {HomePage} from './HomePage'