VS2012, TypeScript & JSON typing - by Stéphane Erard Dev

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 786101 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 5/2/2013 5:24:06 AM
Access Restriction Public

Description


Hi,

I get an important error when I past this JSON in my ts file, which makes it impossible to compile (that's why I mark it as important).

var s = { "media": [
                        {
                            "@type": "image",
                            "@id": "4",
                            "@detailedtype": "",
                            "@minx": "0",
                            "@miny": "0",
                            "@mincropx": "0",
                            "@mincropy": "0",
                            "@maxcropx": "1",
                            "@maxcropy": "1",
                            "@url": "",
                            "@name": "",
                            "@maxx": "",
                            "@maxy": "",
                            "@originalwidth": "0",
                            "@originalheight": "0"
                        },
                        {
                            "@type": "sound",
                            "@id": "3",
                            "@url": "",
                            "meta-data": {
                                "name": null,
                                "description": null
                            }
                        }
                      ]};
Sign in to post a comment.
Posted by Stéphane Erard Dev on 5/6/2013 at 3:03 PM
Hi,

Thank you for your reply !

So I can write something like :

var s = <any[]> { "media": [
                        {
                            "@type": "image",
                            "@id": "4",
                            "@detailedtype": "",
                            "@minx": "0",
                            "@miny": "0",
                            "@mincropx": "0",
                            "@mincropy": "0",
                            "@maxcropx": "1",
                            "@maxcropy": "1",
                            "@url": "",
                            "@name": "",
                            "@maxx": "",
                            "@maxy": "",
                            "@originalwidth": "0",
                            "@originalheight": "0"
                        },
                        {
                            "@type": "sound",
                            "@id": "3",
                            "@url": "",
                            "meta-data": {
                                "name": null,
                                "description": null
                            }
                        }
                     ]};

? (I do not have VS2012 here to test).

I'll post my future TS-related comments at typescript.codeplex.com, thank you !
Posted by Microsoft on 5/6/2013 at 2:57 PM
Thanks for your feedback. I believe the current behavior is by design, as your array literal has objects with different properties, thus there is no 'common type'. If you assert your array literal as an <any[]> the error will go away.

Note that the TypeScript team uses the Issue Tracker on our CodePlex site at http://typescript.codeplex.com/ to interact with customer issues. Please continue to engage with us here if you have further issues.

Thanks!
Posted by Microsoft on 5/2/2013 at 11:52 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 5/2/2013 at 5:54 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)