| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| tests/cases/compiler/throwType_function_parameter.ts(4,24): error TS2345: Argument of type 'number' is not assignable to parameter of type 'never'. | ||
| tests/cases/compiler/throwType_function_parameter.ts(4,24): error TS2899: Type instantiated results in a throw type saying: | ||
| No zero | ||
| tests/cases/compiler/throwType_function_parameter.ts(13,4): error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'. | ||
| tests/cases/compiler/throwType_function_parameter.ts(13,4): error TS2899: Type instantiated results in a throw type saying: | ||
| "found ""str"" | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/throwType_function_parameter.ts (4 errors) ==== | ||
| function checkParameterPosition<T extends number>(y: T extends 1234 ? throw 'No zero' : T) { | ||
| y.toExponential() | ||
| } | ||
| checkParameterPosition(1234) | ||
| ~~~~ | ||
| !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'never'. | ||
| ~~~~ | ||
| !!! error TS2899: Type instantiated results in a throw type saying: | ||
| !!! error TS2899: No zero | ||
| checkParameterPosition(12345678) | ||
|
|
||
| type MustNumber<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| type MustNumber2<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| function f2<T>(a: MustNumber<T>, b: MustNumber2<T>) { | ||
| a = b | ||
| } | ||
|
|
||
| f2('str', {}) | ||
| ~~~~~ | ||
| !!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'. | ||
| ~~~~~ | ||
| !!! error TS2899: Type instantiated results in a throw type saying: | ||
| !!! error TS2899: "found ""str"" | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //// [throwType_function_parameter.ts] | ||
| function checkParameterPosition<T extends number>(y: T extends 1234 ? throw 'No zero' : T) { | ||
| y.toExponential() | ||
| } | ||
| checkParameterPosition(1234) | ||
| checkParameterPosition(12345678) | ||
|
|
||
| type MustNumber<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| type MustNumber2<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| function f2<T>(a: MustNumber<T>, b: MustNumber2<T>) { | ||
| a = b | ||
| } | ||
|
|
||
| f2('str', {}) | ||
|
|
||
|
|
||
| //// [throwType_function_parameter.js] | ||
| function checkParameterPosition(y) { | ||
| y.toExponential(); | ||
| } | ||
| checkParameterPosition(1234); | ||
| checkParameterPosition(12345678); | ||
| function f2(a, b) { | ||
| a = b; | ||
| } | ||
| f2('str', {}); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| === tests/cases/compiler/throwType_function_parameter.ts === | ||
| function checkParameterPosition<T extends number>(y: T extends 1234 ? throw 'No zero' : T) { | ||
| >checkParameterPosition : Symbol(checkParameterPosition, Decl(throwType_function_parameter.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 0, 32)) | ||
| >y : Symbol(y, Decl(throwType_function_parameter.ts, 0, 50)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 0, 32)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 0, 32)) | ||
|
|
||
| y.toExponential() | ||
| >y.toExponential : Symbol(Number.toExponential, Decl(lib.es5.d.ts, --, --)) | ||
| >y : Symbol(y, Decl(throwType_function_parameter.ts, 0, 50)) | ||
| >toExponential : Symbol(Number.toExponential, Decl(lib.es5.d.ts, --, --)) | ||
| } | ||
| checkParameterPosition(1234) | ||
| >checkParameterPosition : Symbol(checkParameterPosition, Decl(throwType_function_parameter.ts, 0, 0)) | ||
|
|
||
| checkParameterPosition(12345678) | ||
| >checkParameterPosition : Symbol(checkParameterPosition, Decl(throwType_function_parameter.ts, 0, 0)) | ||
|
|
||
| type MustNumber<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| >MustNumber : Symbol(MustNumber, Decl(throwType_function_parameter.ts, 4, 32)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 6, 16)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 6, 16)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 6, 16)) | ||
| >TypeToString : Symbol(TypeToString, Decl(lib.es5.d.ts, --, --)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 6, 16)) | ||
|
|
||
| type MustNumber2<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| >MustNumber2 : Symbol(MustNumber2, Decl(throwType_function_parameter.ts, 6, 79)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 7, 17)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 7, 17)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 7, 17)) | ||
| >TypeToString : Symbol(TypeToString, Decl(lib.es5.d.ts, --, --)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 7, 17)) | ||
|
|
||
| function f2<T>(a: MustNumber<T>, b: MustNumber2<T>) { | ||
| >f2 : Symbol(f2, Decl(throwType_function_parameter.ts, 7, 80)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 8, 12)) | ||
| >a : Symbol(a, Decl(throwType_function_parameter.ts, 8, 15)) | ||
| >MustNumber : Symbol(MustNumber, Decl(throwType_function_parameter.ts, 4, 32)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 8, 12)) | ||
| >b : Symbol(b, Decl(throwType_function_parameter.ts, 8, 32)) | ||
| >MustNumber2 : Symbol(MustNumber2, Decl(throwType_function_parameter.ts, 6, 79)) | ||
| >T : Symbol(T, Decl(throwType_function_parameter.ts, 8, 12)) | ||
|
|
||
| a = b | ||
| >a : Symbol(a, Decl(throwType_function_parameter.ts, 8, 15)) | ||
| >b : Symbol(b, Decl(throwType_function_parameter.ts, 8, 32)) | ||
| } | ||
|
|
||
| f2('str', {}) | ||
| >f2 : Symbol(f2, Decl(throwType_function_parameter.ts, 7, 80)) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| === tests/cases/compiler/throwType_function_parameter.ts === | ||
| function checkParameterPosition<T extends number>(y: T extends 1234 ? throw 'No zero' : T) { | ||
| >checkParameterPosition : <T extends number>(y: T extends 1234 ? throw 'No zero' : T) => void | ||
| >y : T extends 1234 ? never : T | ||
|
|
||
| y.toExponential() | ||
| >y.toExponential() : string | ||
| >y.toExponential : (fractionDigits?: number) => string | ||
| >y : T extends 1234 ? never : T | ||
| >toExponential : (fractionDigits?: number) => string | ||
| } | ||
| checkParameterPosition(1234) | ||
| >checkParameterPosition(1234) : void | ||
| >checkParameterPosition : <T extends number>(y: T extends 1234 ? never : T) => void | ||
| >1234 : 1234 | ||
|
|
||
| checkParameterPosition(12345678) | ||
| >checkParameterPosition(12345678) : void | ||
| >checkParameterPosition : <T extends number>(y: T extends 1234 ? never : T) => void | ||
| >12345678 : 12345678 | ||
|
|
||
| type MustNumber<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| >MustNumber : MustNumber<T> | ||
|
|
||
| type MustNumber2<T> = T extends number ? T : throw `"found "${TypeToString<T>}"` | ||
| >MustNumber2 : MustNumber2<T> | ||
|
|
||
| function f2<T>(a: MustNumber<T>, b: MustNumber2<T>) { | ||
| >f2 : <T>(a: MustNumber<T>, b: MustNumber2<T>) => void | ||
| >a : MustNumber<T> | ||
| >b : MustNumber2<T> | ||
|
|
||
| a = b | ||
| >a = b : MustNumber2<T> | ||
| >a : MustNumber<T> | ||
| >b : MustNumber2<T> | ||
| } | ||
|
|
||
| f2('str', {}) | ||
| >f2('str', {}) : void | ||
| >f2 : <T>(a: MustNumber<T>, b: MustNumber2<T>) => void | ||
| >'str' : "str" | ||
| >{} : {} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| tests/cases/compiler/throwType_function_return.ts(5,1): error TS2899: Type instantiated results in a throw type saying: | ||
| Cannot divided by 0 | ||
| tests/cases/compiler/throwType_function_return.ts(10,1): error TS2899: Type instantiated results in a throw type saying: | ||
| Wrong | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/throwType_function_return.ts (2 errors) ==== | ||
| 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) | ||
| ~~~~~~~~~~~~~~~~ | ||
| !!! error TS2899: Type instantiated results in a throw type saying: | ||
| !!! error TS2899: Cannot divided by 0 | ||
| checkedDivide(1) | ||
|
|
||
| const theAnswerToEverything = <T>(x: T): T extends 42 ? T : throw "Wrong" => x | ||
| theAnswerToEverything(42 as const) | ||
| theAnswerToEverything('') | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2899: Type instantiated results in a throw type saying: | ||
| !!! error TS2899: Wrong | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //// [throwType_function_return.ts] | ||
| 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('') | ||
|
|
||
|
|
||
| //// [throwType_function_return.js] | ||
| function checkedDivide(x) { | ||
| if (x === 0) | ||
| throw new Error(''); | ||
| return 5 / x; | ||
| } | ||
| checkedDivide(0); | ||
| checkedDivide(1); | ||
| var theAnswerToEverything = function (x) { return x; }; | ||
| theAnswerToEverything(42); | ||
| theAnswerToEverything(''); |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIMO, NameOf<T> might be a better name.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThat issue requires a runtime behavior but this one is only type-level. I don't know if it is a good idea to use NameOf
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.