admin管理员组文章数量:1430531
When I write typescript:
I have this code:
import * as express from 'express'
and the system gives me an error:
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
So, I change to:
import express from 'express'
what is the difference between them, why the first way can not called or constructed?
When I write typescript:
I have this code:
import * as express from 'express'
and the system gives me an error:
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
So, I change to:
import express from 'express'
what is the difference between them, why the first way can not called or constructed?
Share Improve this question asked Apr 30, 2019 at 5:12 user504909user504909 9,55916 gold badges74 silver badges113 bronze badges 1-
as
is used when you want to givealias name
. – random Commented Apr 30, 2019 at 5:14
1 Answer
Reset to default 8what is the difference between them
* as express
will import the entire contents of a moduleexpress
is will import the default export only
why the first way can not called or constructed?
A module itself is not callable as per the ES spec. So you wouldn't be able to do express()
i.e. a function invocation. Therefore it must mapped to a member of the module, in this case the default
export member
本文标签: typescriptwhat different between import * as module and import module in javascriptStack Overflow
版权声明:本文标题:typescript - what different between import * as module and import module in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745506768a2661280.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论