简体   繁体   English

打字稿:谁能解释这个代码块

[英]Typescript: Can anyone explain this code block

I'm trying to understand existing code block in a project, I'm a Javascript developer and I'm not aware of TypeScript alot 我正在尝试了解项目中的现有代码块,我是Javascript开发人员,并且不了解TypeScript。

Code block:: 代码块:

ViewModel newPropertyAddress = new ViewModel(){name, previousPro = oldValue }

That is not valid TypeScript as far as I am aware. 据我所知,那是无效的TypeScript。 ViewModel newPropertyAddress is not how you create a new variable of type ViewModel in TypeScript - that would be const newPropertyAddress: ViewModel . ViewModel newPropertyAddress不是您如何在TypeScript中创建ViewModel类型的新变量的方法,该变量将是const newPropertyAddress: ViewModel

To say nothing of the bizarre curly brace block, which is technically speaking valid TS, but I can't imagine who would write any code like that, or why. 更不用说奇怪的花括号了,从技术上讲这是合法的TS,但是我无法想象谁会写这样的代码,或者为什么。

This is how i learned and solved it. 这就是我学习和解决它的方式。

ViewModel newPropertyAddress = new ViewModel();
newPropertyAddress.name = getName();
newPropertyAddress.previousPro = oldValue;

Thanks for Stackoverflow ComCommunity. 感谢Stackoverflow社区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM