Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27656,6 +27656,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer;
}
else {
// Check if there's a type symbol with the same name
const typeSymbol = resolveName(node, node.escapedText, SymbolFlags.Type, /*nameNotFoundMessage*/ undefined, /*isUse*/ false);
if (typeSymbol && !(typeSymbol.flags & SymbolFlags.Value)) {
return Diagnostics.Cannot_find_name_0_1_only_refers_to_a_type_but_is_being_used_as_a_value_here;
}
Comment on lines +27660 to +27663
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The diagnostic message requires two parameters ('{0}' for the identifier name and '{1}' for the type symbol name), but the current implementation doesn't provide a way to pass the second parameter. When this diagnostic is used in onFailedToResolveSymbol (line 3282 in checker.ts), it will call error(errorLocation, nameNotFoundMessage, diagnosticName(nameArg)) which only provides one argument. You need to either: (1) change the diagnostic message to only use one parameter like the existing "'{0}' only refers to a type, but is being used as a value here." (code 2693), or (2) modify the error reporting mechanism to pass both the identifier name and the type symbol name as separate arguments. The existing diagnostic 2693 might already serve this purpose.

Copilot uses AI. Check for mistakes.
return Diagnostics.Cannot_find_name_0;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2828,6 +2828,10 @@
"category": "Error",
"code": 2552
},
"Cannot find name '{0}'. '{1}' only refers to a type, but is being used as a value here.": {
"category": "Error",
"code": 2888
},
Comment on lines +2831 to +2834
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The error code 2888 is significantly out of sequence. It's placed between codes 2552 and 2553 in the file, but 2888 is over 300 codes higher. This breaks the sequential ordering convention used throughout the file. The code should likely be 2553 or the next available sequential code in the 2500s range to maintain consistency with the surrounding diagnostic codes.

Copilot uses AI. Check for mistakes.
"Computed values are not permitted in an enum with string valued members.": {
"category": "Error",
"code": 2553
Expand Down
26 changes: 26 additions & 0 deletions tests/cases/compiler/typeAliasUsedAsValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @filename: mytypes.ts
export class MyClass {
public a: number;
}

export type MyClassAlias = MyClass;

// @filename: main.ts
import {MyClassAlias} from './mytypes';

let a: MyClassAlias = new MyClassAlias(); // Error: should show better message
let b = MyClassAlias; // Error: should show better message

// Test with local type alias
type LocalAlias = string;
let c = LocalAlias; // Error: should show better message

// Test with interface
interface MyInterface {
prop: string;
}
let d = MyInterface; // Error: should show better message

// Test with generic type alias
type GenericAlias<T> = T[];
let e = GenericAlias; // Error: should show better message
Loading