{"action":"created","issue":{"url":"https://api.github.com/repos/google/j2cl/issues/23","repository_url":"https://api.github.com/repos/google/j2cl","labels_url":"https://api.github.com/repos/google/j2cl/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/google/j2cl/issues/23/comments","events_url":"https://api.github.com/repos/google/j2cl/issues/23/events","html_url":"https://github.com/google/j2cl/issues/23","id":393748871,"node_id":"MDU6SXNzdWUzOTM3NDg4NzE=","number":23,"title":"Using @JsProperty for properties with periods in the name causes type errors","user":{"login":"assafgelber","id":2394509,"node_id":"MDQ6VXNlcjIzOTQ1MDk=","avatar_url":"https://avatars2.githubusercontent.com/u/2394509?v=4","gravatar_id":"","url":"https://api.github.com/users/assafgelber","html_url":"https://github.com/assafgelber","followers_url":"https://api.github.com/users/assafgelber/followers","following_url":"https://api.github.com/users/assafgelber/following{/other_user}","gists_url":"https://api.github.com/users/assafgelber/gists{/gist_id}","starred_url":"https://api.github.com/users/assafgelber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/assafgelber/subscriptions","organizations_url":"https://api.github.com/users/assafgelber/orgs","repos_url":"https://api.github.com/users/assafgelber/repos","events_url":"https://api.github.com/users/assafgelber/events{/privacy}","received_events_url":"https://api.github.com/users/assafgelber/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-23T13:11:46Z","updated_at":"2018-12-24T16:50:44Z","closed_at":null,"author_association":"NONE","body":"Hi, thanks for your work on this project!\r\nI'm not entirely sure whether this is a bug or a feature request, but definitely an interesting case I ran into.\r\n\r\n**Describe the bug**\r\n\r\nI am trying to use the (archived, yet still in prod) [Settings API in B2G](https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/API/Settings_API) using JsInterop types. Very briefly, the [`SettingsLock#get(key)`](https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/API/SettingsLock/get) method takes a settings key (which is generally [one of these](https://github.com/mozilla-b2g/gaia/blob/975a35c0f5010df341e96d6c5ec60217f5347412/build/config/common-settings.json)), and returns a `DOMRequest` object. If reading from settings succeeds, the request's result object will look something like this:\r\n\r\n```javascript\r\n\"result\": {\r\n  \"deviceinfo.os\": \"2.0.0\"\r\n}\r\n```\r\nSo, in this case, the value I am interested in is `\"2.0.0\"`.\r\n\r\nHere is a **very simplified** version of the types I'm using:\r\n```java\r\n// Navigator.java\r\n\r\n@JsType(isNative = true, namespace = JsPackage.GLOBAL)\r\npublic class Navigator {\r\n\r\n    @JsProperty(name = \"mozSettings\")\r\n    public native SettingsManager getSettings();\r\n}\r\n\r\n// SettingsManager.java\r\n\r\n@JsType(isNative = true, namespace = JsPackage.GLOBAL)\r\npublic class SettingsManager {\r\n\r\n    @JsMethod\r\n    public native SettingsLock createLock();\r\n}\r\n\r\n// SettingsLock.java\r\n\r\n@JsType(isNative = true, namespace = JsPackage.GLOBAL)\r\npublic class SettingsLock {\r\n\r\n    @JsMethod\r\n    public native <T> DOMRequest<T> get(String key);\r\n}\r\n\r\n// Callback.java\r\n\r\n@JsFunction\r\npublic class Callback {\r\n    public run();\r\n}\r\n\r\n// DOMRequest.java\r\n\r\n@JsType(isNative = true, namespace = JsPackage.GLOBAL)\r\npublic class DOMRequest<T> {\r\n\r\n    @JsProperty\r\n    public native T getResult();\r\n\r\n    @JsProperty(name = \"onsuccess\")\r\n    public native void setOnSuccess(Callback onSuccess);\r\n}\r\n\r\n// DeviceOSResult.java\r\n\r\n@JsType(isNative = true, namespace = JsPackage.GLOBAL)\r\npublic class DeviceOSResult {\r\n\r\n    @JsProperty(name = \"deviceinfo.os\")\r\n    public native String getDeviceOS();\r\n}\r\n```\r\n\r\nAnd then I would want to use this like so:\r\n```java\r\n// DeviceSettings.java\r\n\r\npublic class DeviceSettings {\r\n\r\n    public void getDeviceOS(Navigator navigator) {\r\n        SettingsLock lock = navigator.getSettings().createLock();\r\n        DOMRequest<DeviceOSResult> request = lock.get(\"deviceinfo.os\");\r\n        request.setOnSuccess(() -> {\r\n            String os = request.getResult().getDeviceOS();\r\n            // Do something with OS\r\n        });\r\n    }\r\n}\r\n\r\n```\r\n\r\nThis code transpiles to (simplified):\r\n\r\n```javascript\r\nvar os = request.result.deviceinfo.os;\r\n```\r\n\r\nAnd then instead of the value, as you may expect, I get:\r\n\r\n```\r\nTypeError: Cannot read property 'os' of undefined\r\n```\r\n\r\nYou can try reproduce this with the code above.\r\n\r\n**Expected behavior**\r\n\r\nThis is definitely a strange API, and indeed it was not accepted and didn't make it's way into the spec. It is still implemented in B2G, however, and there are devices in the wild using it.\r\n\r\nThat being said, ideally, I would expect this to transpile to something like:\r\n\r\n```javascript\r\nvar os = request.result[\"deviceinfo.os\"];\r\n```\r\n\r\nHowever, I would be happy to hear from you all if there might be a better, simpler way of getting this value from the result object, since this is such a niche API.\r\nSo I'm happy to hear other options or discuss how to potentially fix properties like this.\r\n\r\nEither way, thank you for you time! 💟💟💟"},"comment":{"url":"https://api.github.com/repos/google/j2cl/issues/comments/449754309","html_url":"https://github.com/google/j2cl/issues/23#issuecomment-449754309","issue_url":"https://api.github.com/repos/google/j2cl/issues/23","id":449754309,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0OTc1NDMwOQ==","user":{"login":"assafgelber","id":2394509,"node_id":"MDQ6VXNlcjIzOTQ1MDk=","avatar_url":"https://avatars2.githubusercontent.com/u/2394509?v=4","gravatar_id":"","url":"https://api.github.com/users/assafgelber","html_url":"https://github.com/assafgelber","followers_url":"https://api.github.com/users/assafgelber/followers","following_url":"https://api.github.com/users/assafgelber/following{/other_user}","gists_url":"https://api.github.com/users/assafgelber/gists{/gist_id}","starred_url":"https://api.github.com/users/assafgelber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/assafgelber/subscriptions","organizations_url":"https://api.github.com/users/assafgelber/orgs","repos_url":"https://api.github.com/users/assafgelber/repos","events_url":"https://api.github.com/users/assafgelber/events{/privacy}","received_events_url":"https://api.github.com/users/assafgelber/received_events","type":"User","site_admin":false},"created_at":"2018-12-24T16:50:44Z","updated_at":"2018-12-24T16:50:44Z","author_association":"NONE","body":"Thanks for your reply!\r\nCould you point me to what exactly do you mean by `JsMap`, I couldn't find any info about apart from [this class](https://github.com/ArcBees/gwtquery/blob/master/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java) in GwtQuery. Is that what you mean?"}}
{"actor":{"display_login":"assafgelber"}}