Title: The inferred type of `this` is wrong · Issue #8913 · microsoft/TypeScript · GitHub
Open Graph Title: The inferred type of `this` is wrong · Issue #8913 · microsoft/TypeScript
X Title: The inferred type of `this` is wrong · Issue #8913 · microsoft/TypeScript
Description: On this file declare var require:any; var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); // Populate property map with ReactJS's attribute and property mappings // TODO handle/use .Properties value eg: MUST_USE_PROPE...
Open Graph Description: On this file declare var require:any; var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); // Populate property map with ReactJS's attribute and property mappings // TODO handle/...
X Description: On this file declare var require:any; var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); // Populate property map with ReactJS's attribute and property mappings // ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/8913
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The inferred type of `this` is wrong","articleBody":"On this file\n\n``` ts\ndeclare var require:any;\n\nvar HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig');\n\n// Populate property map with ReactJS's attribute and property mappings\n// TODO handle/use .Properties value eg: MUST_USE_PROPERTY is not HTML attr\nfor (var propname in HTMLDOMPropertyConfig.Properties) {\n if (!HTMLDOMPropertyConfig.Properties.hasOwnProperty(propname)) {\n continue;\n }\n\n var mapFrom = HTMLDOMPropertyConfig.DOMAttributeNames[propname] || propname.toLowerCase();\n}\n\n/**\n * Repeats a string a certain number of times.\n * Also: the future is bright and consists of native string repetition:\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat\n *\n * @param {string} string String to repeat\n * @param {number} times Number of times to repeat string. Integer.\n * @see http://jsperf.com/string-repeater/2\n */\nfunction repeatString(string, times) {\n if (times === 1) {\n return string;\n }\n if (times \u003c 0) { throw new Error(); }\n var repeated = '';\n while (times) {\n if (times \u0026 1) {\n repeated += string;\n }\n if (times \u003e\u003e= 1) {\n string += string;\n }\n }\n return repeated;\n}\n\n/**\n * Determine if the string ends with the specified substring.\n *\n * @param {string} haystack String to search in\n * @param {string} needle String to search for\n * @return {boolean}\n */\nfunction endsWith(haystack, needle) {\n return haystack.slice(-needle.length) === needle;\n}\n\n/**\n * Trim the specified substring off the string. If the string does not end\n * with the specified substring, this is a no-op.\n *\n * @param {string} haystack String to search in\n * @param {string} needle String to search for\n * @return {string}\n */\nfunction trimEnd(haystack, needle) {\n return endsWith(haystack, needle)\n ? haystack.slice(0, -needle.length)\n : haystack;\n}\n\n/**\n * Convert a hyphenated string to camelCase.\n */\nfunction hyphenToCamelCase(string) {\n return string.replace(/-(.)/g, function(match, chr) {\n return chr.toUpperCase();\n });\n}\n\n/**\n * Determines if the specified string consists entirely of whitespace.\n */\nfunction isEmpty(string) {\n return !/[^\\s]/.test(string);\n}\n\n/**\n * Determines if the CSS value can be converted from a\n * 'px' suffixed string to a numeric value\n *\n * @param {string} value CSS property value\n * @return {boolean}\n */\nfunction isConvertiblePixelValue(value) {\n return /^\\d+px$/.test(value);\n}\n\nexport class HTMLtoJSX {\n private output: string;\n private level: number;\n private _inPreTag: boolean;\n\n\n /**\n * Handles processing of the specified text node\n *\n * @param {TextNode} node\n */\n _visitText = (node) =\u003e {\n var parentTag = node.parentNode \u0026\u0026 node.parentNode.tagName.toLowerCase();\n if (parentTag === 'textarea' || parentTag === 'style') {\n // Ignore text content of textareas and styles, as it will have already been moved\n // to a \"defaultValue\" attribute and \"dangerouslySetInnerHTML\" attribute respectively.\n return;\n }\n\n var text = ''\n\n if (this._inPreTag) {\n // If this text is contained within a \u003cpre\u003e, we need to ensure the JSX\n // whitespace coalescing rules don't eat the whitespace. This means\n // wrapping newlines and sequences of two or more spaces in variables.\n text = text\n .replace(/\\r/g, '')\n .replace(/( {2,}|\\n|\\t|\\{|\\})/g, function(whitespace) {\n return '{' + JSON.stringify(whitespace) + '}';\n });\n } else {\n // If there's a newline in the text, adjust the indent level\n if (text.indexOf('\\n') \u003e -1) {\n }\n }\n this.output += text;\n }\n\n\n\n};\n\n/**\n * Handles parsing of inline styles\n */\nexport class StyleParser {\n styles = {};\n toJSXString = () =\u003e {\n for (var key in this.styles) {\n if (!this.styles.hasOwnProperty(key)) {\n }\n }\n }\n}\n```\n\n\u003e which is actually a part of a larger file [here](https://github.com/alm-tools/alm/blob/master/src/app/htmlToJsx/htmlToJsx.ts)\n\nWith TypeScript nightly we get the following errors: \n\n```\nC:/repos/alm/tests/success/simple/bas.tsx:141 Property 'styles' does not exist on type 'HTMLtoJSX'.\nC:/repos/alm/tests/success/simple/bas.tsx:142 Property 'styles' does not exist on type 'HTMLtoJSX'.\n```\n\nBasically `this` in the class function isn't inferring to `StyleParser` and instead inferring to `HTMLtoJSX`\n\n``` ts\nexport class StyleParser {\n styles = {};\n toJSXString = () =\u003e {\n for (var key in this.styles) {\n if (!this.styles.hasOwnProperty(key)) {\n }\n }\n }\n}\n```\n\nSorry for not being able to narrow it down, deleting portions of the file (e.g. the `HTMLtoJSX._visitText` method) makes the error go away. Note that this error only appeared in the last 10 days :rose: \n","author":{"url":"https://github.com/basarat","@type":"Person","name":"basarat"},"datePublished":"2016-06-01T06:57:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/8913/TypeScript/issues/8913"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:189088ff-9425-2275-5d1d-dbefc22c6130 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F20:2FDF33:2C2F7C6:402704E:6A60DC9D |
| html-safe-nonce | 63cb4c853a24c3247fe7ef35307e554d481dc35d8a68487959a40d0da9e32945 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjIwOjJGREYzMzoyQzJGN0M2OjQwMjcwNEU6NkE2MERDOUQiLCJ2aXNpdG9yX2lkIjoiMTI3MDQ5MzA3OTMxODYxNzI0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 025e7e172f345e60645f0507cc9f778207d00fd482c441e55be11ffcda88f661 |
| hovercard-subject-tag | issue:157836446 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/8913/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c03e7b2d70e49381777f680fb94f358650e179ad07fe4104d7175a5f29fa4a4/microsoft/TypeScript/issues/8913 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c03e7b2d70e49381777f680fb94f358650e179ad07fe4104d7175a5f29fa4a4/microsoft/TypeScript/issues/8913 |
| og:image:alt | On this file declare var require:any; var HTMLDOMPropertyConfig = require('react/lib/HTMLDOMPropertyConfig'); // Populate property map with ReactJS's attribute and property mappings // TODO handle/... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | basarat |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8302bdfafed4cf34ac9c1d3593108fafa53bc3f86b893907e38fa6bdd74361ac |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c3c2ff0c76b34772c83c9498a08cefee28f53da0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width