diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9e1086a98e5..43cff3cb523 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26192,6 +26192,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return compilerOptions.types ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode; + case "Bun": + return compilerOptions.types + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun; case "Map": case "Set": case "Promise": diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8a16147b633..5a71fa894b1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3735,6 +3735,14 @@ "category": "Error", "code": 2866 }, + "Cannot find name '{0}'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun`.": { + "category": "Error", + "code": 2867 + }, + "Cannot find name '{0}'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun` and then add 'bun' to the types field in your tsconfig.": { + "category": "Error", + "code": 2868 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/typingsSuggestionBun1.errors.txt b/tests/baselines/reference/typingsSuggestionBun1.errors.txt new file mode 100644 index 00000000000..c2ab614b5fc --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun1.errors.txt @@ -0,0 +1,11 @@ +a.ts(1,14): error TS2868: Cannot find name 'Bun'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun` and then add 'bun' to the types field in your tsconfig. + + +==== tsconfig.json (0 errors) ==== + { "compilerOptions": {"types": []} } + +==== a.ts (1 errors) ==== + const file = Bun.file("/a.ts"); + ~~~ +!!! error TS2868: Cannot find name 'Bun'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun` and then add 'bun' to the types field in your tsconfig. + \ No newline at end of file diff --git a/tests/baselines/reference/typingsSuggestionBun1.js b/tests/baselines/reference/typingsSuggestionBun1.js new file mode 100644 index 00000000000..4561a2ff4ae --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun1.js @@ -0,0 +1,8 @@ +//// [tests/cases/conformance/typings/typingsSuggestionBun1.ts] //// + +//// [a.ts] +const file = Bun.file("/a.ts"); + + +//// [a.js] +var file = Bun.file("/a.ts"); diff --git a/tests/baselines/reference/typingsSuggestionBun1.symbols b/tests/baselines/reference/typingsSuggestionBun1.symbols new file mode 100644 index 00000000000..77b6c8f7174 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun1.symbols @@ -0,0 +1,6 @@ +//// [tests/cases/conformance/typings/typingsSuggestionBun1.ts] //// + +=== a.ts === +const file = Bun.file("/a.ts"); +>file : Symbol(file, Decl(a.ts, 0, 5)) + diff --git a/tests/baselines/reference/typingsSuggestionBun1.types b/tests/baselines/reference/typingsSuggestionBun1.types new file mode 100644 index 00000000000..2961bd44872 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun1.types @@ -0,0 +1,11 @@ +//// [tests/cases/conformance/typings/typingsSuggestionBun1.ts] //// + +=== a.ts === +const file = Bun.file("/a.ts"); +>file : any +>Bun.file("/a.ts") : any +>Bun.file : any +>Bun : any +>file : any +>"/a.ts" : "/a.ts" + diff --git a/tests/baselines/reference/typingsSuggestionBun2.errors.txt b/tests/baselines/reference/typingsSuggestionBun2.errors.txt new file mode 100644 index 00000000000..309dc7e05b3 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun2.errors.txt @@ -0,0 +1,11 @@ +a.ts(1,14): error TS2867: Cannot find name 'Bun'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun`. + + +==== tsconfig.json (0 errors) ==== + { "compilerOptions": {} } + +==== a.ts (1 errors) ==== + const file = Bun.file("/a.ts"); + ~~~ +!!! error TS2867: Cannot find name 'Bun'. Do you need to install type definitions for Bun? Try `npm i --save-dev @types/bun`. + \ No newline at end of file diff --git a/tests/baselines/reference/typingsSuggestionBun2.js b/tests/baselines/reference/typingsSuggestionBun2.js new file mode 100644 index 00000000000..7a19ff2b841 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun2.js @@ -0,0 +1,8 @@ +//// [tests/cases/conformance/typings/typingsSuggestionBun2.ts] //// + +//// [a.ts] +const file = Bun.file("/a.ts"); + + +//// [a.js] +var file = Bun.file("/a.ts"); diff --git a/tests/baselines/reference/typingsSuggestionBun2.symbols b/tests/baselines/reference/typingsSuggestionBun2.symbols new file mode 100644 index 00000000000..e022b8f6d61 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun2.symbols @@ -0,0 +1,6 @@ +//// [tests/cases/conformance/typings/typingsSuggestionBun2.ts] //// + +=== a.ts === +const file = Bun.file("/a.ts"); +>file : Symbol(file, Decl(a.ts, 0, 5)) + diff --git a/tests/baselines/reference/typingsSuggestionBun2.types b/tests/baselines/reference/typingsSuggestionBun2.types new file mode 100644 index 00000000000..e68cee2f35e --- /dev/null +++ b/tests/baselines/reference/typingsSuggestionBun2.types @@ -0,0 +1,11 @@ +//// [tests/cases/conformance/typings/typingsSuggestionBun2.ts] //// + +=== a.ts === +const file = Bun.file("/a.ts"); +>file : any +>Bun.file("/a.ts") : any +>Bun.file : any +>Bun : any +>file : any +>"/a.ts" : "/a.ts" + diff --git a/tests/cases/conformance/typings/typingsSuggestionBun1.ts b/tests/cases/conformance/typings/typingsSuggestionBun1.ts new file mode 100644 index 00000000000..aff75faff5d --- /dev/null +++ b/tests/cases/conformance/typings/typingsSuggestionBun1.ts @@ -0,0 +1,5 @@ +// @filename: tsconfig.json +{ "compilerOptions": {"types": []} } + +// @filename: a.ts +const file = Bun.file("/a.ts"); diff --git a/tests/cases/conformance/typings/typingsSuggestionBun2.ts b/tests/cases/conformance/typings/typingsSuggestionBun2.ts new file mode 100644 index 00000000000..6c07e0483d3 --- /dev/null +++ b/tests/cases/conformance/typings/typingsSuggestionBun2.ts @@ -0,0 +1,5 @@ +// @filename: tsconfig.json +{ "compilerOptions": {} } + +// @filename: a.ts +const file = Bun.file("/a.ts");