René's URL Explorer Experiment


Title: Proposal: Easier Migration with Loose Mode in TypeScript Files · Issue #22665 · microsoft/TypeScript · GitHub

Open Graph Title: Proposal: Easier Migration with Loose Mode in TypeScript Files · Issue #22665 · microsoft/TypeScript

X Title: Proposal: Easier Migration with Loose Mode in TypeScript Files · Issue #22665 · microsoft/TypeScript

Description: This issue is the dual of #23906. Background TypeScript has always aimed at making migration from JavaScript as easy as possible; however, even today there exists a bit of an awkward gap where you must rewrite your JavaScript code to put...

Open Graph Description: This issue is the dual of #23906. Background TypeScript has always aimed at making migration from JavaScript as easy as possible; however, even today there exists a bit of an awkward gap where you ...

X Description: This issue is the dual of #23906. Background TypeScript has always aimed at making migration from JavaScript as easy as possible; however, even today there exists a bit of an awkward gap where you ...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/22665

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Easier Migration with Loose Mode in TypeScript Files","articleBody":"This issue is the dual of #23906.\r\n\r\n# Background\r\n\r\nTypeScript has always aimed at making migration from JavaScript as easy as possible; however, even today there exists a bit of an awkward gap where you must rewrite your JavaScript code to put it in a state where it's \"ready\" to be converted to TypeScript. As an example, users might start annotating their code with JSDoc to get better analysis in `.js` files, but once they switch their file extensions to `.ts`, TypeScript pretends like it doesn't understand those annotations anymore.\r\n\r\n# Proposal\r\n\r\nTypeScript can provide a new \"loose\" mode (which we'll refer to as `looseTs`). This loose mode can be seen as a hybrid between the `allowJs`/Salsa language service support for JavaScript, along with TypeScript itself.\r\n\r\nLet's explore what would this experience would look like.\r\n\r\n## Special JavaScript Declarations Are Allowed\r\n\r\nTypeScript would understand certain constructs that are currently special cased in JS files. For example, the following construct would create what TypeScript effectively sees as a constructor.\r\n\r\n```ts\r\nfunction Foo() {\r\n    this.x = 10;\r\n    this.y = 20;\r\n    this.z = 30;\r\n}\r\n\r\nnew Foo().x + new Foo().y + new Foo().z // all well-typed as 'number'\r\n```\r\n\r\nOur language service could provide tooling to help refactor this to a more canonical sort of class.\r\n\r\n## Type Annotations & Declarations\r\n\r\nAll TypeScript constructs would continue to work, but so would JSDoc annotations & declarations.\r\n\r\n```ts\r\n/**\r\n * @typedef {PersonName} string\r\n */\r\n\r\nexport interface Person {\r\n    // valid to reference JSDoc declarations in the same file\r\n    name: PersonName;\r\n}\r\n```\r\n\r\nTypeScript constructs would always take precedent over their JSDoc counterparts when they potentially conflict. For example, the following provides an error at worst, but will always consider `x` to be a `string`:\r\n\r\n```ts\r\n/**\r\n * @type {number}\r\n */\r\nvar x: string;\r\n```\r\n\r\n## Class Properties\r\n\r\nToday, TypeScript requires all classes to have property declarations.\r\n\r\nFuture versions of ECMAScript might *allow* property declarations.\r\n\r\nThe story here is: pick one. If classes contain no property declarations, then we'll fall back to Salsa-style inference from the constructor body. If any property declarations are present, then any access to `this` with a member that hasn't been declared is an error.\r\n\r\n```ts\r\n// Good!\r\nclass AllDeclared {\r\n    a: number;\r\n    constructor() {\r\n        this.a = 0;\r\n    }\r\n}\r\n\r\n// Good!\r\n// Also, users get a quick fix.\r\nclass OnlyInitialized {\r\n    constructor() {\r\n        this.a = 0;\r\n    }\r\n}\r\n\r\n// Bad!\r\nclass MixedDeclarationsAndInitialization {\r\n    a: number;\r\n    constructor() {\r\n        this.a = 10;\r\n        this.b = \"hallo\";\r\n    }\r\n}\r\n```\r\n\r\nWe can provide tooling to help migrate users to TypeScript code that declares all of the initialized properties.\r\n\r\n## Best-Effort Completions\r\n\r\nLike in Salsa, we should provide loose completions for things like `any` by default. This might be editor-configurable, but see #5334 for some more discussion.\r\n\r\n## More?\r\n\r\nYour ideas here!\r\n\r\n# Drawbacks\r\n\r\nOne argument is that this could potentially dilute the value of the language, similar to concerns around `// @ts-ignore`.\r\n\r\nAnother related argument has to do with cognitive overhead. Our heuristics around understanding JavaScript constructs in Salsa (our JS language service) feels somewhat opaque. While we can document what special constructs we support, TypeScript's current model is significantly simpler. It might not be clear what features \"proper TypeScript\" actually supports (i.e. what exactly are you giving up when you turn off `looseTs`?)\r\n\r\n# Alternatives\r\n\r\nWe may want to consider alternatives before we commit to something like this.\r\n\r\n## Type Annotations in JavaScript Files\r\n\r\nThis proposal has proposed the idea of understanding Salsa/JS constructs in `.ts` files, but one could approach it from the other direction: Salsa could support type annotations in `.js` files instead under a specific mode. Our main concern here has been the conflation between what is possible in JavaScript today, and what constructs are specific to TypeScript. Additionally, providing non-standard constructs in `.js` files might give users the wrong impression over what we're trying to achieve (to clarify, in this issue, we're here to provide tooling for JavaScript users and make it easier to migrate to TypeScript).\r\n\r\n## Tooling Tooling Tooling Tooling\r\n\r\nNow that we have suggestion diagnostics, we can potentially provide suggestions & tooling to just fix \"legacy\" JS constructs in the language service once you've moved to TypeScript. The counter-point here is that users will still likely experience the \"sea of red\" problem when you first switch a file over to `.ts`.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2018-03-16T23:18:50Z","url":"https://github.com/microsoft/TypeScript/issues/22665"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:27f24130-6646-495d-c61b-60a5d7748a87
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC78E:20AA01:38200E9:4749306:6B01DCC4
html-safe-nonce007b895a9b8f398db2fab14f8277e3deb48710c8e8844ec5da2c876db6bce93d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzhFOjIwQUEwMTozODIwMEU5OjQ3NDkzMDY6NkIwMURDQzQiLCJ2aXNpdG9yX2lkIjoiOTExNTk5MTM0OTM3NDYwNjUzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca627f831f0cc6d6e4e3d12b9e596c9d6350ec01adc82e14651970c40372244f5
hovercard-subject-tagissue:306103421
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/22665/issue_layout
twitter:imagehttps://opengraph.githubassets.com/979574aff7e3cfd1d7c4784aa42902a5ede0111e84e1b30eaac05094f3c3f254/microsoft/TypeScript/issues/22665
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/979574aff7e3cfd1d7c4784aa42902a5ede0111e84e1b30eaac05094f3c3f254/microsoft/TypeScript/issues/22665
og:image:altThis issue is the dual of #23906. Background TypeScript has always aimed at making migration from JavaScript as easy as possible; however, even today there exists a bit of an awkward gap where you ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameDanielRosenwasser
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/22665#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F22665
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F22665
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/22665
Reloadhttps://github.com/microsoft/TypeScript/issues/22665
Reloadhttps://github.com/microsoft/TypeScript/issues/22665
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/22665
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/22665
Proposal: Easier Migration with Loose Mode in TypeScript Fileshttps://github.com/microsoft/TypeScript/issues/22665#top
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Mar 16, 2018https://github.com/microsoft/TypeScript/issues/22665#issue-306103421
#23906https://github.com/microsoft/TypeScript/issues/23906
#5334https://github.com/microsoft/TypeScript/issues/5334
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Mar 16, 2018https://github.com/microsoft/TypeScript/issues/22665#event-1526593723
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Mar 17, 2018https://github.com/microsoft/TypeScript/issues/22665#issuecomment-373876307
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Mar 17, 2018https://github.com/microsoft/TypeScript/issues/22665#issuecomment-373957356
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
on Jul 25, 2018https://github.com/microsoft/TypeScript/issues/22665#event-1753534651
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Aug 13, 2018https://github.com/microsoft/TypeScript/issues/22665#event-1786345895
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/22665
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/22665
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.