What is "TC39: Type Annotations" aka the Types as Comments proposal

Rate this content
Bookmark
The TC59 Type Annotations proposal, also known as Types with Comments, is discussed in this video. This proposal aims to treat type annotations in JavaScript as comments, allowing them to be ignored by JavaScript engines. The video highlights the significance of TypeScript and its growing influence on the JavaScript ecosystem. The proposal's main goal is to separate TypeScript's type features from JavaScript's runtime features, addressing concerns about Microsoft's influence on the language. The video also covers the stages of a TC39 proposal, the impact of TypeScript on JavaScript, and the potential benefits of the TC59 proposal. Community involvement and research are emphasized as crucial for the proposal's progress. The proposal is currently at stage one in the TC39 process, and the video encourages viewers to follow the GitHub repo and participate in community surveys.

From Author:

A deep dive into the proposal which could de-fork TypeScript and bring all us users back to being "JavaScripters, but with some TypeScript types." We'll cover the author's motives, how it could work, why now and how it is going.ort

This talk has been presented at TypeScript Congress 2023, check out the latest edition of this Tech Conference.

FAQ

The TC59 Type Annotations proposal, also known as Types with Comments, is a proposal aimed at allowing typed code to run in JavaScript by treating type annotations as comments that JavaScript engines can ignore.

TC39 is a group of developers focused on evolving JavaScript in a slow and safe manner. They work on developing and refining proposals that help enhance the language through a structured stage-based process.

A TC39 proposal goes through five stages, each increasing in specificity and detail, starting from an initial idea to a fully accepted modification of the JavaScript language.

The TC59 proposal adds constraints to TypeScript, potentially allowing TypeScript and JavaScript to converge more closely by treating TypeScript's type annotations as comments in JavaScript code.

The proposal has gained importance due to the widespread adoption and proven need for typed JavaScript, as evidenced by the popularity of TypeScript. It aims to incorporate types in JavaScript in a manner that aligns with existing scripting languages like Ruby and Python.

TypeScript has significantly influenced the JavaScript ecosystem, often considered a fork of JavaScript. The proposal aims to unfork TypeScript by integrating its type syntax as comments in JavaScript, thereby aligning both languages more closely.

The 'types as comments' approach in the TC59 proposal suggests that browsers and JavaScript engines should treat type annotations as comments, thereby ignoring them during execution but utilizing them for development purposes like static checking.

The proposal could simplify the development process by allowing types to be used in JavaScript without affecting runtime performance. It also aims to standardize how types are handled across different environments, reducing the complexity for developers.

Orta Therox
Orta Therox
27 min
21 Sep, 2023

Comments

Sign in or register to post your comment.
  • Denis Radin
    Denis Radin
    GitNation Foundation
    Looking forward to ts being a standard! Cool intent!

Video Transcription

1. Introduction to TC59 Type Annotations Proposal

Short description:

We're going to go through the TC59 Type Annotations proposal, a.k.a. Types with Comments, which adds the ability to run typed code in JavaScript. The proposal is currently at stage one in the TC39 process. We'll discuss its underlying concept and how it affects TypeScript.

All right. Hi, everybody. We're going to go through the TC59 Type Annotations proposal, a.k.a. Types with Comments. This is a proposal that adds the ability to run typed code in JavaScript.

Now, my name is Otto the Rocks. I used to work on the TypeScript team for about two and a half years. During that time I worked on website and documentation and a little bit of compiler features here and there. And one of my favorite things when I left was I had this great, like, YouTube video that describes the entire compiler process that's really, really useful if you're, you know, into understanding the tools that you use on an everyday basis.

So, to get this talk started, we want to at least have some shared vocabulary. We're going to talk a bit about TC39. There are a group of folks whose entire goal is to try and figure out how to evolve JavaScript slowly and safely. And the way in which they do this is sort of by making these proposals. These proposals, you know, they go through five stages. They're all sort of more and more specific over time. And we're talking about a TC39 proposal that is now at stage one.

So, the proposal itself is what we're going to go into first. We'll go over that briefly. We'll dig into why now makes some sense. Because it's not the first. We'll see how it affects TypeScript. That's kind of the majority. And we'll sort of go into where it's going next. So, this is the underlying concept. That there's a problem with this code. That it will not run in a JavaScript engine. Like the colon string is going to throw. And that means that that's not legitimate language. So, we want to be in a position where that does not happen. How to do that? That's the tricky question that people have asked a lot.

2. The Proposal's Impact on TypeScript and JavaScript

Short description:

This proposal argues that JavaScript engines should treat the code as a comment, allowing browsers to ignore it. It is not a traditional comment, but rather a way to indicate that the code should be ignored. TypeScript has shown the need for typed JavaScript, and this proposal builds on prior languages like Ruby and Python. The main focus is on how this proposal affects TypeScript and brings it back into JavaScript.

And this proposal argues that the way to do that is to say that, hey, JavaScript engines, you just ignore this code. You treat it as a comment. Now, comments are already pretty well defined in JavaScript. You've got a slash, slash. We'll do it to the end of the line. And you've got a slash, star. We'll do it to the end of a star, slash. This is us using the term a little bit ambiguously. It isn't a comment in the way in which we normally think of them. But it is telling both the person who is trying to understand this proposal, the idea is, you just ignore it. And we teach browsers how to ignore that type of code. And that is the idea.

If you want to really dig into the details, you can go to the TypeScript's, the TypeScript comments, I'm going to make that mistake a bunch. The Typescript comments proposal web page. And this is a higher-level version of the proposal. So it doesn't require you to be a language nerd, basically. And if you do want to really nerd out, you should watch Gil Tyre's talk on the lead up to his proposal, because he's one of the folks pushing it. How and why he got some consensus from a bunch of folks. And sort of why it makes sense in the long run in comparison to him using JSDoc support in JavaScript.

So why now? Right? Like, you know, there has been many attempts at trying to add a type system to JavaScript. And this is sort of the first time that one has sort of got to a level of, you know, people caring. TypeScript I think has really proven to folks that there's a need for typed JavaScript at a reasonable scale. TypeScript itself is now in a position where it's okay to sort of take on some of the constraints that would be necessary to make this work. And the idea's already been proven in prior languages that have similar constraints, like scripty type of languages, like Ruby and Python. The extent to which they fully agree with all of the tradeoffs is something that we can now use to figure out what that should look like in JavaScript in comparison to sort of Ruby and Python's implementation, too. So we're not the first, we're trying something new. We're trying something that's reasonably established.

Now, the thing that I think most people are in the context of TS Congress are interested in is how does this affect TypeScript, right? This is a proposal that adds some constraints to TypeScript that can sort of maybe bring TypeScript back into JavaScript. There's a lot of things going on here. And when I thought about how to frame this, I went through the notes from TC39's original discussion, and spotted that Rob Palmer had this beautiful sentence that sums it all up.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Guide to React Rendering Behavior
React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize React rendering.
Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
Watch video: React's Most Useful Types
Today's Talk focuses on React's best types and JSX. It covers the types of JSX and React components, including React.fc and React.reactnode. The discussion also explores JSX intrinsic elements and react.component props, highlighting their differences and use cases. The Talk concludes with insights on using React.componentType and passing components, as well as utilizing the react.element ref type for external libraries like React-Select.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
TypeScript and React: Secrets of a Happy Marriage
React Advanced Conference 2022React Advanced Conference 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
React and TypeScript have a strong relationship, with TypeScript offering benefits like better type checking and contract enforcement. Failing early and failing hard is important in software development to catch errors and debug effectively. TypeScript provides early detection of errors and ensures data accuracy in components and hooks. It offers superior type safety but can become complex as the codebase grows. Using union types in props can resolve errors and address dependencies. Dynamic communication and type contracts can be achieved through generics. Understanding React's built-in types and hooks like useState and useRef is crucial for leveraging their functionality.

Workshops on related topic

React Hooks Tips Only the Pros Know
React Summit Remote Edition 2021React Summit Remote Edition 2021
177 min
React Hooks Tips Only the Pros Know
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
The addition of the hooks API to React was quite a major change. Before hooks most components had to be class based. Now, with hooks, these are often much simpler functional components. Hooks can be really simple to use. Almost deceptively simple. Because there are still plenty of ways you can mess up with hooks. And it often turns out there are many ways where you can improve your components a better understanding of how each React hook can be used.You will learn all about the pros and cons of the various hooks. You will learn when to use useState() versus useReducer(). We will look at using useContext() efficiently. You will see when to use useLayoutEffect() and when useEffect() is better.
React, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Featured Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Designing Effective Tests With React Testing Library
React Summit 2023React Summit 2023
151 min
Designing Effective Tests With React Testing Library
Top Content
Featured Workshop
Josh Justice
Josh Justice
React Testing Library is a great framework for React component tests because there are a lot of questions it answers for you, so you don’t need to worry about those questions. But that doesn’t mean testing is easy. There are still a lot of questions you have to figure out for yourself: How many component tests should you write vs end-to-end tests or lower-level unit tests? How can you test a certain line of code that is tricky to test? And what in the world are you supposed to do about that persistent act() warning?
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced Conference 2022React Advanced Conference 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.