3.0.0-alpha.12
vue create hello-world
使用 TypeScript 和使用 class-style 风格组件cd hello-world
yarn serve
or yarn build
Success
提示:
Property 'msg' has no initializer and is not definitely assigned in the constructor.
没有修改任何文件,创建默认项目后运行报错。
无法重现,可能是你的 npm 缓存问题。看下你的 components/HelloWorld.vue
文件是否是这样的:
export default class HelloWorld extends Vue {
@Prop() private msg!: string;
}
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.
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 the compilerOptions
object within the tsconfig.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.
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?
remove "strict": true,
@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.
Most helpful comment
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.