stc icon indicating copy to clipboard operation
stc copied to clipboard

stc fails to find type alias circular references

Open awareness481 opened this issue 2 years ago • 1 comments

Given this input

type A = A2;
type A2 = A;

stc will print image

Log

ERROR (1) Failed to find type: A2#2
    at crates/stc_ts_file_analyzer/src/analyzer/scope/mod.rs:2261
    in Expander::expand_ref
    in Expander::expand_type
    in Expander::expand_type
    in Expander::expand_ref
    in Expander::expand_type
    in expand
    in normalize with ty: A;
    in normalize with ty: A;
    in Stmt with line_col: "(2017:1-2017:13)"

but for a non-circular reference stc will find the type just fine

type A = A2;
type A2 = number;

declare var x: A;
x = "" // error cant assign string to type number

My guess is that having a self-referencing type breaks how type aliases are hoisted (which I presume they are hoisted), but i haven't been able to confirm.

awareness481 avatar Apr 17 '23 07:04 awareness481

stc calculated evaluation order based on the dependency graph, but it can't handle cycles yet.

kdy1 avatar Apr 17 '23 07:04 kdy1