Closed
Description
Version
3.0.0-alpha.12
Steps to reproduce
vue create hello-world
使用 TypeScript 和使用 class-style 风格组件cd hello-world
yarn serve
oryarn build
What is expected?
Success
What is actually happening?
提示:
Property 'msg' has no initializer and is not definitely assigned in the constructor.
没有修改任何文件,创建默认项目后运行报错。
Activity
yyx990803 commentedon Feb 13, 2018
无法重现,可能是你的 npm 缓存问题。看下你的
components/HelloWorld.vue
文件是否是这样的:nothingstopi commentedon Feb 14, 2018
I have seen the same error with 3.0.0-alpha.13.

One thing I noticed that main.ts is not generated, but main.js instead.
But main.ts was considered as the entry point. See pic below:
So I changed main.js to main.ts, and I saw the error/warnings below.:

But the page on the browser is showing correctly.
Darkseal commentedon Feb 18, 2018
The issue is most likely related to the
strictPropertyInitialization
flag introduced in TypeScript 2.7, which is also set to TRUE by default (see official docs).If you're using TS 2.7, try to turn it off by adding a
"strictPropertyInitialization": false
setting to thecompilerOptions
object within thetsconfig.json
root file: if that doesn't fix it, try to temporarily downgrade to TS 2.6 and see if the error persists.For a detailed explanation of the issue and some possible workarounds/fixes, read this post.
falknerdominik commentedon Aug 20, 2018
Hi,
I know that it is a bad habit to comment on closed issues, but what @Darkseal posted is just a workaround. Will the generate support strict property initialization in the future?
adminparry commentedon Apr 29, 2019
remove "strict": true,
shirshak55 commentedon Mar 5, 2020
@adminparry no why to remove strict? Whats the point of using type system then? As even said using bang to tell typesystem the value is initialized is good choice . Removing strict can allow other bugs thats why i never recommend it.
[BUGFIX] Fix error message of props not having an initializer