GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Throw types by Jack-Works · Pull Request #40468 · microsoft/TypeScript

Conversation

@Jack-Works

@Jack-Works Jack Works (Jack-Works) commented Sep 10, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #23689

Playground: https://www.staging-typescript.org/play?ts=4.2.0-pr-40468-44

This PR introduces:

  1. A new type-level expression: throw type_expr. Currently throw type only throws when it is being instantiated.
  2. A new intrinsic type TypeToString to print a type.

Considered use cases:

Welcome to suggest more use cases!

TypeAlias instantation

type MustNumber<T> = T extends number ? T : throw `Expected, but found "${TypeToString<T>}"`
type A = MustNumber<1>
type B = MustNumber<typeof window>

image

Prevent CallExpression

function checkedDivide<T extends number>(x: T): T extends 0 ? throw 'Cannot divided by 0' : number {
    if (x === 0) throw new Error('')
    return 5 / x
}
checkedDivide(0)
checkedDivide(1)

const theAnswerToEverything = <T>(x: T): T extends 42 ? T : throw "Wrong" => x
theAnswerToEverything(42 as const)
theAnswerToEverything('')

function checkParameterPosition<T extends number>(y: T extends 1234 ? throw 'No zero' : T) { }
checkParameterPosition(1234)
checkParameterPosition(12345678)

image

Prevent use of identifiers

image

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

crutchcorn, XGHeaven, kdnk, g-plane, bluebill1049, 0kku, cherryblossom000, whatasoda, solson, NN---, and 181 more reacted with thumbs up emoji eczn, artalar, phuctm97, 5ay3h, nachocodoner, SwapnilSoni1999, hennihaus, dankochetov, and bgoscinski reacted with laugh emoji pocesar, swyxio, robpalme, jbt95, evelynhathaway, davidkpiano, harrysolovay, promer94, luizcieslak, dsherret, and 89 more reacted with heart emoji artalar, phuctm97, fxlrnrpt, 3Shain, atsixian, SwapnilSoni1999, Colisan, slaesh, anuraghazra, dschmidt, and 8 more reacted with rocket emoji tom-sherman, crutchcorn, bluebill1049, Waldo000000, mmkal, reiv, Artazor, Klaster1, nikosdouvlis, kettanaito, and 18 more reacted with eyes emoji
All reactions
  • 👍 191 reactions
  • 😄 9 reactions
  • ❤️ 99 reactions
  • 🚀 18 reactions
  • 👀 28 reactions
Jack Works (Jack-Works) added 6 commits September 10, 2020 11:56
@Jack-Works
feat: introduce throw type
1befac3
@Jack-Works
feat: handle throw type in call expression
2a9f067
@Jack-Works
feat: add typeof modifier in template string
f1286b6
@Jack-Works
chore: accept baseline
1c1c653
@Jack-Works
fix: un-instantiate throw type in return type
22c76cf
@Jack-Works
fix: throw type parse error at true branch of conditional type
241cc97
@typescript-bot TypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 10, 2020
@Jack-Works Jack Works (Jack-Works) mentioned this pull request Sep 10, 2020
Throw types #40402
Closed
@Jack-Works
feat: add throw type check for identifier
530c395
@Jack-Works Jack Works (Jack-Works) mentioned this pull request Sep 10, 2020
Dangerous "name" (and potentially others) global #18433
Open
@Jack-Works
fix: lint error
d69f2b0
@orta

Orta Therox (orta) commented Sep 10, 2020

Copy link
Copy Markdown
Contributor

TypeScript Bot (@typescript-bot) pack this

mmkal, occar421, sahandevs, and jonathan-emed reacted with heart emoji
All reactions
  • ❤️ 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 10, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at d69f2b0. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 10, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey Orta Therox (@orta), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/84753/artifacts?artifactName=tgz&fileId=458CBB664D3CE9EFA165B438F01414D55349C27455F3F7CE2CC288A173FC410B02&fileName=/typescript-4.1.0-insiders.20200910.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mmkal Misha Kaletsky (mmkal) mentioned this pull request Sep 10, 2020
feat: use throw types for better error messages mmkal/ts#152
Closed
@Jack-Works

Jack Works (Jack-Works) commented Sep 10, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Idea: Find a way to "match" the error string into the typescript diagnostic object, to reuse the translation of diagnostic message.

A possible solution:

throw {diagnostic: "Did_you_mean_0", args: [T] }

That will match the Diagnostic.Did_you_mean_0 and therefore it will be automatically translated by the compiler.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works

Jack Works (Jack-Works) commented Sep 10, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Idea: Find a way to emit other kinds of diagnostic, like suggestions or warning. If so, there should be another mechanism to offer a underlying type like

throw {message: T, type: T2, kind: "suggestion"}
swyxio, sahandevs, rabbit-source, and pkb-pmj reacted with thumbs up emoji
All reactions
  • 👍 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works

Jack Works (Jack-Works) commented Sep 10, 2020

Copy link
Copy Markdown
Contributor Author

Oh I just realized we can throw a object type so it can include more details! Please help me to investigate the possibility of this to find a good shape of the error object.

Possible properties:

  • underlying type (what should this throw type resolve to)
  • diagnosis level (error, suggestions, warning, deprecation)
  • reference to typescript built in diagnosis message to provide translated message
  • provide refactor suggestions
swyxio, ethanresnick, rabbit-source, and pkb-pmj reacted with heart emoji
All reactions
  • ❤️ 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dsherret
David Sherret (dsherret) reviewed Sep 11, 2020
View reviewed changes
Comment thread src/compiler/diagnosticMessages.json Outdated
"category": "Error",
"code": 2793
},
"Type instantiated results in a throw type saying: {0}": {

@dsherret David Sherret (dsherret) Sep 11, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something shorter? Type instantiation threw. {0}?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

harrysolovay, Colisan, Methrat0n, alii, and wihlke-vntrs reacted with thumbs up emoji Jack-Works reacted with eyes emoji
All reactions
  • 👍 5 reactions
  • 👀 1 reaction
@Jack-Works

Jack Works (Jack-Works) commented Sep 11, 2020

Copy link
Copy Markdown
Contributor Author

Idea: Allow throw type to be handled by conditional type. This allows some error recovery or composing multiple errors.

T extends throw infer E1 ?
    U extends throw infer E2 ?
        throw `\n    ${E1}\n    ${E2}`
    : T : never
eczn, Beraliv, Renegatto, alii, and jankuca reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works

Jack Works (Jack-Works) commented Sep 11, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author
import type { DiagnosticCategory } from 'typescript'
/**
 * Since this is a type-level thing, any union in this type is considered invalid value
 * cause their value is not determinate yet.
 * 
 * `throw "string"` is convert to `throw { message: "string" }`
 */
type ErrorMessage = {
    /**
     * ! implemented !
     * If diagnostic is not exist or not valid (key not found / not a tuple) this message will be used
     * 
     * If it is not a string literal type, it will be formatted by `getTypeNameForErrorDisplay`
     */
    message: any
    /**
     * What type should this throw type compatible(equal) with?
     * Useful to "add" diagnostic message on a type and preserve itself
     * @default never
     */
    type?: any
    /**
     * ! implemented !
     * TODO: provide completion for this in the language service
     * Actually it is `[keyof Diagnostic (a @internal variable of ts), ...any[]]`
     * @example ["_0_expected", T] results in "T expected" (with translation in different languages)
     */
    diagnostic?: [type: string, ...args: any[]]
    /**
     * ! implemented !
     * @default `Error` when undefined. `Message` when value is invalid.
     */
    category?: 'suggestion' | 'error' | 'warning' | 'message'
    /**
     * It seems like deprecated is not in the DiagnosticCategory
     */
    deprecated?: boolean

    // ! Let developers custom the error code might not a good idea.
    // code: number

    /**
     * When it happened on an identifer, replace the identifier with the suggestion
     * e.g.: name => window.name
     * 
     * When it happened on a type alias, do nothing
     * When it happened on a CallExpression, do nothing
     * 
     * ? Is this really useful cause the throw cannot get the original source text ?
     * 
     * If we have higher kind types, this option can receive a un-instantiated generic type
     * as a type-level function.
     * 
     * @example
     * type MyError<Context extends ...> = ...
     * type T<U> = ... extends ... ? ... : throw {message: ..., suggestion: MyError}
     */
    suggestion?: string

    /**
     * Let message be able to chain
     */
    next?: ErrorMessage | ErrorMessage[]
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works

Jack Works (Jack-Works) commented Sep 11, 2020

Copy link
Copy Markdown
Contributor Author

Idea: Find a way to "match" the error string into the typescript diagnostic object, to reuse the translation of diagnostic message.

A possible solution:

throw {diagnostic: "Did_you_mean_0", args: [T] }

That will match the Diagnostic.Did_you_mean_0 and therefore it will be automatically translated by the compiler.

image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works
feat: able to reference translated diagnostic message
b5f4fce
@Jack-Works

Jack Works (Jack-Works) commented Sep 11, 2020

Copy link
Copy Markdown
Contributor Author

Idea: Find a way to emit other kinds of diagnostic, like suggestions or warning. If so, there should be another mechanism to offer a underlying type like

throw {message: T, type: T2, kind: "suggestion"}

izayl reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works
feat: support category in throw type
b39ff3d
@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as draft September 11, 2020 07:10
@Harpush

Harpush commented Sep 11, 2020

Copy link
Copy Markdown

To be honest the initial idea is great - but adding diagnostics types and formatting feels like an overkill. It might even step into the linters world. The syntax is more complex too. I think having the ability to throw is already great as is.

harrysolovay, fatihcoskun79, mmkal, rabbit-source, and Just-Helpful reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works

Jack Works (Jack-Works) commented Sep 11, 2020

Copy link
Copy Markdown
Contributor Author

The syntax is more complex too.

Hmm, I didn't introduce a new syntax for a "detailed" throw. It's a plain object literal type. I need some advice from the TypeScript team. If they think it's no need to do this, I'll stop working on that feature sets and focus on what will be accepted.

Now I still have two complex ideas:

  • Detailed throw (throw { ... }) (Throw types #40468 (comment))
  • Conditional type support (Throw types #40468 (comment))

Is there anything I mentioned above that the TS team doesn't want? cc Ryan Cavanaugh (@RyanCavanaugh) Orta Therox (@orta) Wenlu Wang (@Kingwl)

tonivj5 reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tom-sherman

Tom Sherman (tom-sherman) commented Sep 11, 2020

Copy link
Copy Markdown

Should the playground link posted by TypeScript Bot (@typescript-bot) be able to run the examples in the PR description? I'm not able to see the error messages as in the screenshot

https://www.staging-typescript.org/play?ts=4.1.0-pr-40468-3#code/C4TwDgpgBAsgrgZ2AOTgWwEYQE4B4AqAfFALxT5QQAewEAdgCYJR3pbZQD85UAXFMAAW2APYB3KAAMAolUgBjWgwA0UDHGBQAZiLiMoAIgAkAb1CQRW8gF8DkgFDnoAQVKxEKNjlwBGQo-BoACE3eCRUTG8nSygxAEtGcX8gA

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works

Jack Works (Jack-Works) commented Sep 11, 2020

Copy link
Copy Markdown
Contributor Author

Oh, I'm sorry it's a regression (bug) Tom Sherman (@tom-sherman) I'll fix it soon. You can try an old version https://www.staging-typescript.org/play?ts=4.1.0-pr-40402-15 (but it has other bugs)

tom-sherman reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bitgopatmcl Patrick McLaughlin (bitgopatmcl) mentioned this pull request Jul 19, 2022
feat: produce helpful error messages on httpRequest codec errors BitGo/api-ts#168
Merged
@Andarist Mateusz Burzyński (Andarist) mentioned this pull request Aug 12, 2022
Contextual type can't be provided to a mapped type intersected with an object type #48812
Closed
@delucca Daniel De Lucca Fonseca (delucca) mentioned this pull request Aug 16, 2022
feat(common): more verbose tsc error message on wrong provider declaration nestjs/nest#10109
Closed
3 of 12 tasks
@shicks

Stephen Hicks (shicks) commented Aug 25, 2022

Copy link
Copy Markdown
Contributor

I'm excited to see that this is still being (somewhat) actively developed. As a library developer, I would absolutely love to see this land. Any idea how to get the necessary attention for this to move forward?

mmkal, SferaDev, AugustinLF, Th3Whit3Wolf, slaesh, axmrnv, thelinuxlich, pkb-pmj, ashsmith, dylan-dang, and 11 more reacted with thumbs up emoji
All reactions
  • 👍 21 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nopeless

nopeless (nopeless) commented Sep 25, 2022

Copy link
Copy Markdown

It always excites me when you are looking for a feature and some devs have been working on it for years. Yes I would love a "throw" type because some type checks require extraneous chaining of type generics and it can be hard to deliver semantic reasoning

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Jack Works (Jack-Works) added 2 commits September 25, 2022 15:03
@Jack-Works
Merge branch 'main' into throwTypes
361bb7b
@Jack-Works
fix: lint
ea2c58d
@ssalbdivad

David Blass (ssalbdivad) commented Sep 25, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Daniel Rosenwasser (@DanielRosenwasser) Is it possible to get a quick update on the team's plans for this PR? It has received a lot of interest and support from the community and been open for over 2 years now. The author recently stated:

Once I get the guide (code review or design) from the TypeScript team, I can continue on this PR. Without their input, there isn't much I can do because the experiment is basically done.

While his diligence is admirable, he's kind of in a difficult spot having to continually make updates like this without any assurances as to when his work will be merged, if ever.

Jack Works (@Jack-Works) Just wanted to thank you for continuing to maintain this for so long!

Jack-Works, darrylnoakes, shicks, phpnode, kmannislands, ccrsxx, svew, papb, blakepettersson, trevorade, and 9 more reacted with heart emoji
All reactions
  • ❤️ 19 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works
fix: test failed
a995c42
@trevorade Trevor Florence (trevorade) mentioned this pull request Oct 20, 2022
Improve errors. Add actual and expected types to MismatchArgs mmkal/expect-type#13
Closed
@trevorade

Trevor Florence (trevorade) commented Oct 20, 2022

Copy link
Copy Markdown
Contributor

Just pointing out that the https://github.com/mmkal/expect-type TS type-checking library could really benefit from this PR if merged.

Jack Works (@Jack-Works) Thank you for creating this! Excited to hopefully use it!

papb, sindresorhus, and GerkinDev reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@papb

Pedro Augusto de Paula Barbosa (papb) commented Oct 20, 2022

Copy link
Copy Markdown

This is super nice. I have some questions - how (if) would the following constructs work?

type T = throw "oops";
type U = "foo" | throw "oops";
type V = { a?: throw "oops" };
type W = (arg: throw "oops") => any;
type X<T> = T extends throw infer E ? true : false;

Also, if I have type MakeThrow<T extends string> = throw T; can I use MakeThrow<"oops"> everywhere I could use throw T and it will work in the same way?

Also, if throw X is just another type, how does it relate to other common types? For example, does it extend never, any, unknown?

I would suggest making throw "something" extend (i.e. be a subtype of) never. In a way that never becomes the "union of all throw types".

What does everyone think? I suspect having good answers to all these questions is a way to help the PR move forward.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mmkal Misha Kaletsky (mmkal) mentioned this pull request Oct 21, 2022
Drop tsd for tests in favor of expect-type sindresorhus/type-fest#499
Closed
@shicks

Stephen Hicks (shicks) commented Oct 21, 2022

Copy link
Copy Markdown
Contributor

Pedro Augusto de Paula Barbosa (@papb) (rearranging your questions slightly)

This is super nice. I have some questions - how (if) would the following constructs work?
What does everyone think? I suspect having good answers to all these questions is a way to help the PR move forward.

If you look at the files changed in the PR, the tests show what the currently-proposed behavior is. That said, maybe Orta Therox (@orta) could ask the bot to set this up so that you could try them out in the playground?

My understanding (of what at least I'd want) is that error T would give an immediate error (and resolve to never) and time T is an actual concrete type without any type variables.

type T = throw "oops";
type U = "foo" | throw "oops";
type V = { a?: throw "oops" };
type W = (arg: throw "oops") => any;

I would hope all of these would immediately error.

type X<T> = T extends throw infer E ? true : false;

This seems maybe problematic. I can see some value to being able to introspect the errors (particularly for library API testing), but I'd be inclined to move forward without it and really just make it an exact never after issuing the diagnostic. If there's a compelling use for this, it could be done in a future iteration.

Also, if I have type MakeThrow<T extends string> = throw T; can I use MakeThrow<"oops"> everywhere I could use throw T and it will work in the same way?

I would hope so. In MakeThrow's definition, you're throwing a type variable, so it shouldn't error yet. But once you instantiate that type with a concrete string, then it can produce an actual diagnostic.

Also, if throw X is just another type, how does it relate to other common types? For example, does it extend never, any, unknown?

TypeScript already treats type mismatches in a particular way, e.g. if you write declare function foo<T>(arg1: T, arg2: T): T then foo(42, 'x'); will produce a diagnostic, but type checking will continue with treating the erroneous expression as if were any. This feature should be consistent with that.

I would suggest making throw "something" extend (i.e. be a subtype of) never. In a way that never becomes the "union of all throw types".

I don't think "subtype of never" is really a concept we want to open up here. The whole point of never is that it's a subtype of everything, so I think "there be dragons".

papb and darrylnoakes reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@somebody1234

somebody1234 commented Oct 22, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
type X<T> = T extends throw infer E ? true : false;

i'd assume that's intended to behave as a type level try-catch

(of course, definitely a good idea to figure out how useful it would actually be in practice)

papb reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Methrat0n

Methrat0n commented Nov 18, 2022

Copy link
Copy Markdown

Just wanted to bump this up.
I'm also, like everyone else here it seams, working on a library that would greatly benefit from this.
Maybe not a fan of the 'throw' syntax and any more complicated thing than just stopping and showing a compilation error when the type is instantiated as it could create a lot of try catch hell that I've known of to well in Java.
But still, personalising error message for complexe cases is a much feature, I'm sad to see that's it's been so long.

pedrodurek, shicks, SwapnilSoni1999, darrylnoakes, 0kku, ntnyq, and kasper573 reacted with thumbs up emoji pedrodurek reacted with confused emoji
All reactions
  • 👍 7 reactions
  • 😕 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shicks

Stephen Hicks (shicks) commented Nov 19, 2022

Copy link
Copy Markdown
Contributor

My thought is that by the time there's something to "catch", it's already too late - the error has been emitted. Using throw for this is potentially nice because it's been a JS keyword forever, so it's unlikely to clobber any actual existing names. But I dislike any analogy it might make what would suggest to anyone that they can catch it to suppress any error, or really do any sort of logic. Just emit the error and bail out with a never.

papb reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevorade

Trevor Florence (trevorade) commented Nov 19, 2022

Copy link
Copy Markdown
Contributor

Agree that catching it in typing doesn't make sense.

It's a little surprising for me to think about it being recoverable in conjunction with a @ts-ignore. I want to say that @ts-ignore generally resolves weird things to any rather than never. So maybe it would make sense for throw to resolve to an any? If not suppressed, it would just stop compiling anyways.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works Jack Works (Jack-Works) mentioned this pull request Jan 4, 2023
Feature: Self-Type-Checking Types #52088
Closed
@turadg Turadg Aleahmad (turadg) mentioned this pull request Jun 1, 2023
idea: static analysis for unexpected throws sukyoung/safe#40
Open
@Jack-Works

Jack Works (Jack-Works) commented Aug 9, 2023

Copy link
Copy Markdown
Contributor Author

close for housekeeping.

I still have interest in this feature, so I will re-open and rebase it if the TS team also has an interest in it and give some suggestions of its type behavior.

thanks for everyone watching & testing this PR!

lawvs, reiv, iliazeus, xpdmk, karlhorky, tonivj5, eps1lon, cherryblossom000, ssalbdivad, tom-sherman, and 22 more reacted with heart emoji
All reactions
  • ❤️ 32 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jack-Works Jack Works (Jack-Works) closed this Aug 9, 2023
@ssalbdivad

David Blass (ssalbdivad) commented Aug 9, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Jack Works (@Jack-Works) Your work is very much appreciated!

Wanted to take the chance to underscore that since this PR was created in 2020, the most popular libraries in the ecosystem have invested even further in advanced TS features to create the rich DX many devs have come to expect.

Generics that perform some kind of input validation are a common manifestation of this trend, and unfortunately, most library authors end up resorting to TS's builtin solution, never, which is totally opaque when it comes to helping end users resolve the underlying problem.

While some libraries like ArkType have started returning custom error messages instead, the problems I mentioned in my original comment still apply, and the fact that it feels like a hack likely deters a lot of authors from returning anything other than never.

If there is something about this solution in particular that is unsatisfactory, it would be really useful to at least have an idea of what it is so that going forward contributors can avoid repeating it. I can't help but feel a bit sad seeing high-quality contributions like this languish. Everyone involved would greatly benefit from even a very brief explanation of the team's stance.

reiv, tmm, GerkinDev, iliazeus, darrylnoakes, Jack-Works, evelynhathaway, xpdmk, slorber, thelinuxlich, and 27 more reacted with thumbs up emoji shicks, Ericlm, leonadler, cjquines, douglasg14b, ericcrosson-bitgo, and AlaaMouch reacted with heart emoji
All reactions
  • 👍 37 reactions
  • ❤️ 7 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mmkal Misha Kaletsky (mmkal) mentioned this pull request Oct 23, 2022
port throw types PR from mmkal/ts#152 mmkal/expect-type#14
Closed
@jcalz Joe Calzaretta (jcalz) mentioned this pull request Dec 21, 2023
Do not substitute string literals with string when reporting errors #56844
Closed
6 tasks done
@jakebailey Jake Bailey (jakebailey) mentioned this pull request Mar 13, 2024
Proposal: Type Relationship API #9879
Open
@Carolinewly Carolinewly mentioned this pull request Aug 4, 2024
[Snyk] Upgrade expect-type from 0.15.0 to 0.19.0 Carolinewly/ember.js#1
Open
@douglasg14b

Douglas Gaskell (douglasg14b) commented Aug 21, 2024

Copy link
Copy Markdown

Damn, this is a travesty :/

Naddiseo reacted with thumbs down emoji
All reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netanelgilad Netanel Gilad (netanelgilad) mentioned this pull request Aug 6, 2025
Add API key support to created client base44/javascript-sdk#7
Closed
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

Copilot code review Copilot
Copilot will automatically review once the pull request is marked ready for review
2 more reviewers
@dsherret David Sherret (dsherret) dsherret left review comments
@ExE-Boss ExE Boss (ExE-Boss) ExE-Boss left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Proposal: new "invalid" type to indicate custom invalid states

Uh oh!

There was an error while loading. Please reload this page.

20 participants

@Jack-Works @orta @typescript-bot @Harpush @tom-sherman @mmkal @jack-williams @mohe2015 @DanielRosenwasser @Artazor @Andarist @ssalbdivad @nicobrinkkemper @ShayDavidson @typeholes @OnkelTem @SwapnilSoni1999 @Ricardo-Marques @Colisan @Tschrock
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.