Skip to content
New issue

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

Throw types #40468

Closed
wants to merge 34 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1befac3
feat: introduce throw type
Jack-Works Sep 6, 2020
2a9f067
feat: handle throw type in call expression
Jack-Works Sep 6, 2020
f1286b6
feat: add typeof modifier in template string
Jack-Works Sep 6, 2020
1c1c653
chore: accept baseline
Jack-Works Sep 8, 2020
22c76cf
fix: un-instantiate throw type in return type
Jack-Works Sep 10, 2020
241cc97
fix: throw type parse error at true branch of conditional type
Jack-Works Sep 10, 2020
530c395
feat: add throw type check for identifier
Jack-Works Sep 10, 2020
d69f2b0
fix: lint error
Jack-Works Sep 10, 2020
b5f4fce
feat: able to reference translated diagnostic message
Jack-Works Sep 11, 2020
b39ff3d
feat: support category in throw type
Jack-Works Sep 11, 2020
1950b0f
fix: base case of throw types
Jack-Works Sep 11, 2020
9faf8c4
test: add test case for prevent call expr usage
Jack-Works Sep 11, 2020
daac7e7
test: add test for identifier use case
Jack-Works Sep 11, 2020
7d785eb
feat: improve throw type on return type
Jack-Works Sep 12, 2020
c22687f
feat: improve throw type on argument position
Jack-Works Sep 12, 2020
c21c1b7
feat: add property access check for throw type
Jack-Works Sep 12, 2020
94aa731
fix: infinite loop in dropThrowTypeInConditionalType
Jack-Works Sep 12, 2020
56bfcd7
fix: throw type in fn param, co-assign in cond type
Jack-Works Sep 16, 2020
bd0f330
feat: reduce throw type in intersection
Jack-Works Sep 19, 2020
cdd5cd0
Merge branch 'master' into throwTypes
Jack-Works Sep 22, 2020
cfd61cb
Merge branch 'master' into throwTypes
Jack-Works Nov 12, 2020
800fb0c
chore: accept new baseline
Jack-Works Nov 12, 2020
e391bc4
feat: add intrinsic type
Jack-Works Feb 6, 2021
e5e4c0b
Merge branch 'main' into throwTypes
Jack-Works Feb 6, 2021
14c00cc
chore: update baseline
Jack-Works Feb 6, 2021
2303958
fix: linter
Jack-Works Feb 6, 2021
e138279
Merge branch 'main' into throwTypes
Jack-Works Mar 27, 2021
c2ae402
test: update tests
Jack-Works Mar 27, 2021
27df052
Merge branch 'main' into throwTypes
Jack-Works Jul 26, 2021
4f01135
Merge branch 'main' into throwTypes
Jack-Works Feb 14, 2022
e7684dc
fix: test failed
Jack-Works Feb 14, 2022
361bb7b
Merge branch 'main' into throwTypes
Jack-Works Sep 25, 2022
ea2c58d
fix: lint
Jack-Works Sep 25, 2022
a995c42
fix: test failed
Jack-Works Sep 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: un-instantiate throw type in return type
Jack-Works committed Sep 10, 2020
commit 22c76cf357451d01911cb726dd7a34e914304ffd
16 changes: 6 additions & 10 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -1059,14 +1059,9 @@ namespace ts {
return diagnostic;
}

function errorByThrowType(location: Node | undefined, value: Type) {
let message = "Unknown";
if (value.flags & TypeFlags.ThrowType) {
value = (<ThrowType>value).value;
}
if (value.flags & TypeFlags.StringLiteral) {
message = (<StringLiteralType>value).value;
}
function errorByThrowType(location: Node | undefined, type: Type) {
if (type.flags & TypeFlags.ThrowType) type = (<ThrowType>type).value;
const message = getTypeNameForErrorDisplay(type);
error(location, Diagnostics.Type_instantiated_results_in_a_throw_type_saying_Colon_0, message);
}

@@ -15118,6 +15113,7 @@ namespace ts {
function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined;
function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined {
if (!(type && mapper && couldContainTypeVariables(type))) {
if (type && (type.flags & TypeFlags.ThrowType)) errorByThrowType(currentNode, type);
return type;
}
if (instantiationDepth === 50 || instantiationCount >= 5000000) {
@@ -15186,8 +15182,8 @@ namespace ts {
}
}
if (flags & TypeFlags.ThrowType) {
errorByThrowType(currentNode, instantiateType((<ThrowType>type).value, mapper));
return errorType;
const errorMessage = instantiateType((<ThrowType>type).value, mapper);
return createThrowType(errorMessage);
}
return type;
}