R
roblox-ts•3w ago
kv_

Proxy error function does not cause unreachable/terminate thread

I have an error/warning function that will print out standardized error codes to make debugging easier:
export const FATAL = (code: ErrorCode) => {
error('Fatal error occured: ' + code);
};
export const FATAL = (code: ErrorCode) => {
error('Fatal error occured: ' + code);
};
When I call this, the type solver appears to ignore that this function terminates the running thread:
const some_function = () => {
FATAL(ErrorCode.FATAL_BAD_SERVER_RESPONSE);
print('asdfgghjlk') // not marked unreachable
}

const some_function = () => {
const [ok, data] = // call remote function, if ok = true data is not unknown
if (!ok) FATAL(...);
print(data.some_key); // data is of type 'unknown'
}
const some_function = () => {
FATAL(ErrorCode.FATAL_BAD_SERVER_RESPONSE);
print('asdfgghjlk') // not marked unreachable
}

const some_function = () => {
const [ok, data] = // call remote function, if ok = true data is not unknown
if (!ok) FATAL(...);
print(data.some_key); // data is of type 'unknown'
}
This function has no condition for calling error(), so calling it should be effectively the same as calling error(), which does work:
const some_function = () => {
const [ok, data] = // call remote function
if (!ok) error();
print(data.some_key); // no error
}
const some_function = () => {
const [ok, data] = // call remote function
if (!ok) error();
print(data.some_key); // no error
}
Solution:
function FATAL(code: ErrorCode): never {
error("Fatal error occured: " + code);
}
function FATAL(code: ErrorCode): never {
error("Fatal error occured: " + code);
}
...
Jump to solution
23 Replies
Tester
Tester•3w ago
can you make return type :never` ? of the error function
kv_
kv_OP•3w ago
They already are, and it does not fix it
No description
Tester
Tester•3w ago
1 can you try to restart the compiler? Ctrl + Shift + P -> Restart Ts Server
kv_
kv_OP•3w ago
Didn't work 😕
Tester
Tester•3w ago
grrr can you just for test do a manual error or throw there to just test whether [ok, data] type works properly
kv_
kv_OP•3w ago
No description
No description
Tester
Tester•3w ago
what is your typescript version?
kv_
kv_OP•3w ago
5.5.3
Tester
Tester•3w ago
can you upgrade it to 5.9.3? or you use any other transformer besides flamework they apparerntly introduced better type resolution in the newest versions
kv_
kv_OP•3w ago
5.9.3 still has the error and I don't have any other transformer iirc
Tester
Tester•3w ago
error?
kv_
kv_OP•3w ago
the compiler has no issue with it just vscode same, 'out' is of type 'unknown'
Tester
Tester•3w ago
oh yeah... i'm testing it rn
kv_
kv_OP•3w ago
:biggerthink:
Tester
Tester•3w ago
make it a proper function -w-
Solution
Tester
Tester•3w ago
function FATAL(code: ErrorCode): never {
error("Fatal error occured: " + code);
}
function FATAL(code: ErrorCode): never {
error("Fatal error occured: " + code);
}
Tester
Tester•3w ago
it works
Tester
Tester•3w ago
No description
kv_
kv_OP•3w ago
grr incredible Thank you
Tester
Tester•3w ago
yaaay, ywyw it probably thinks that FATAL is some sort of object and cannot be fully trusted cause it's ARROW function
kv_
kv_OP•3w ago
ARROW function is pretty :(
Tester
Tester•3w ago
it's gay! >_< jk
kv_
kv_OP•3w ago
lol

Did you find this page helpful?