Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 786101
Opened: 5/2/2013 5:24:06 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

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
                            }
                        }
                     ]};
Details
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)
Sign in to post a workaround.