Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(TypeScript) Property 'msg' has no initializer and is not definitely assigned in the constructor. #834

Closed
medz opened this issue Feb 13, 2018 · 6 comments

Comments

@medz
Copy link

medz commented Feb 13, 2018

Version

3.0.0-alpha.12

Steps to reproduce

  1. vue create hello-world 使用 TypeScript 和使用 class-style 风格组件
  2. cd hello-world
  3. yarn serve or yarn build

What is expected?

Success

What is actually happening?

提示:

Property 'msg' has no initializer and is not definitely assigned in the constructor.

没有修改任何文件,创建默认项目后运行报错。

@yyx990803
Copy link
Member

无法重现,可能是你的 npm 缓存问题。看下你的 components/HelloWorld.vue 文件是否是这样的:

export default class HelloWorld extends Vue {
  @Prop() private msg!: string;
}

@nothingstopi
Copy link

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:
image

So I changed main.js to main.ts, and I saw the error/warnings below.:
image

But the page on the browser is showing correctly.

@Darkseal
Copy link

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.

@falknerdominik
Copy link

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
Copy link

remove "strict": true,

@shirshak55
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants