Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🔓 Intent to use: checker.isTypeAssignableTo#7936

Discussion options

Overview

Long have we in the TypeScript tooling community spoken of this in hushed tones:microsoft/TypeScript#9879, using a typerelationship API in TypeScript. A typerelationship API would most notably let us determine reliably whether a type is assignable to another type. That ability would be fantastic for a slew of bugs and feature requests: seemicrosoft/TypeScript#9879 (comment) for a list of over a dozen in this repo alone.

TypeScript hasn't yet exposed a type relationship API publicly out of concern for stability and whether the limited set of APIs we're requesting will be sufficient for most or all use cases. Which is very reasonable: the type checker is very complex and has lots of caching internally that can be difficult to predict without deep knowledge of TypeScript program implementations. It's a risky thing to expose these APIs and doubly risky to make them part of a versioned public API.

But! Over the last few years, we've seen several community projects make use of the privatechecker.isTypeAssignableTo API:Arktype,TypeStat, and anassortment from querying public repos on Sourcegraph. This gives us confidence that at least the specificchecker.isTypeAssignableTo API is roughly stable enough for us to at least try out. Perthis thread in the TypeScript Discord asking about usingchecker.isAssignableTo using it is not considered egregious at first glance. Furthermore, seeing how ecosystem projects use the privatechecker.isTypeAssignableTo may even help inform a more formal TypeScript type relationship API later on.

Fun fact:isTypeAssignableTo has been available onTypeChecker objects since roughly TypeScript 3.7.
3.6.5 has undefined3.7.7 has [Function: isTypeAssignableTo]
// index.jsimport{$}from"execa";for(constversionof["3.5","3.6","3.7","3.8"]){await$`npm i typescript@${version}`;await$({stdio:"inherit"})`node ./check.js`;}
// check.jsimporttsfrom"typescript";constprogram=ts.createProgram({rootNames:[],options:{},});console.log(ts.version,"has",program.getTypeChecker().isTypeAssignableTo);

Here is our intent in typescript-eslint:

  1. Do nothing with this information for our current major version,v6 v7
  2. Once v8 is released, we'll addisTypeAssignableTo to the allowlist of private APIs we feel comfortable using, and unblock all issues marked as blocked
  3. If at any point this breaks, we'll do our best to figure out what went wrong and contribute fixes back to TypeScript as needed

🤞 here's hoping it all works out well!

If there are any concerns with this approach or ideas for new lint rule bugfixes or features not yet mentioned inmicrosoft/TypeScript#9879 (comment), we'd love to hear them!


Edit 1 (November 20th, 2023):microsoft/TypeScript#56448 was opened by our friend@jakebailey to make the API public. If it's merged and released, we can close this discussion as irrelevant. 🚀

Edit 2 (December 11th, 2023):microsoft/TypeScript#56448 was merged into TypeScript! Beautiful. To play it safe, I'll wait until a TypeScript RC is released before closing this discussion out.

Edit 3 (February 27th, 2024): Replaced 'v7' with 'v8' as we injected a small v7 version before what was previously going to be our next major.

You must be logged in to vote

Replies: 2 comments

Comment options

JoshuaKGoldberg
Feb 27, 2024
Maintainer Author

https://devblogs.microsoft.com/typescript/announcing-typescript-5-4-rc 🚀

Looks like we can considerchecker.isTypeAssignableTo as ready once v8 is released!

You must be logged in to vote
0 replies
Comment options

JoshuaKGoldberg
Aug 1, 2024
Maintainer Author

Now that typescript-eslint@v8 is released, this is ready to go!

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
1 participant
@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp