javascript - 打字稿类型错误属性不存在
问题描述
我的 Typescript Next 项目中有这个组件
import PageTitle from './pagetitle'
import style from './contact.styl'
export default function Contact() {
return (
<section>
<a name="contact"></a>
<div className={style.container}>
<PageTitle title='get in touch!'/>
<form action="">
<input name="name" type="text" placeholder="name" />
<input name="subject" type="text" placeholder="subject" />
<textarea placeholder="message" />
<button type="submit">send</button>
</form>
</div>
</section>
);
}
这contact.styl
看起来像是一个使用 Stylus CSS PreProcessor 的 CSS 文件,因此样式的拼写没有拼写错误。我最近使用“next-env.d.ts”文件中的模块声明修复了一个错误
.container
width 95vw
height 90vh
display flex
flex-direction column
background rgba(43,43,43,.97)
border-radius 60px
margin 0 auto
h3
font-size 22px
color #d3ecf7
form
height 450px
display flex
flex-direction column
justify-content space-evenly
align-items center
margin-top 3rem
input, textarea
width 355px
box-shadow 0px 3px 6px #00000029
border-radius 13px
outline none
border none
background #2b2b2b
font normal normal 300 20px Avenir
padding-top 5px
text-align center
color #fff
input
height 45px
textarea
height 200px
resize none
::placeholder
text-align center
font normal normal 300 20px Avenir
color #d3ecf7
@media(max-width 760px)
.container
width 100vw
height auto
border-radius 0
form
height 500px
margin-top 0
input, textarea
width 90vw
但我一直收到这个错误?
Type error: Property 'container' does not exist on type 'string'.
谁能帮我弄清楚为什么?
编辑:添加contact.styl
想通了问题
Try to add an asterisk to the module name as in the updated example. **- Sergey**
解决方案
似乎您在声明.d.ts
文件中的某处有一个模块声明。它可能看起来像这样:
declare module ".styl" {
const value: string;
export default value;
}
如果这是正确的,您应该将导出类型更改为Record<string, string>
. 像这样:
declare module "*.styl" {
const value: {[key: string]: string};
export default value;
}
推荐阅读
- json - Shopify 在前端打印自定义文本字段
- php - Firebase查询按数组过滤多个键包含在PHP中?
- android - savedInstanceState 是 null 并且 onSaveInstanceState 没有被调用
- javascript - w3schools.com 的模态图像关闭预览不起作用
- javascript - 使用 await 关键字对多个 API 调用的性能影响
- javascript - ({} + '') 和 {} + '' 有什么区别?
- javascript - 如何从 HTML5 Canvas 创建单个 PNG img?
- laravel - 后端删除后如何使移动个人访问令牌失效?
- arrays - 并非我的数组的所有元素都在同时使用(swift)
- google-cloud-platform - GCP 服务帐号密钥轮换