Improve types for `System` module
Closed this issue · 0 comments
marmitar commented
I was just verifying some types for System
and both addressOf
and exit
seem like they have imprecise typings. I'm not sure if it is actually intended or not, so I'm opening this issue for discussion.
Return type of System.exit
System.exit
is marked with void
instead of never
. Consider using never
, like @types/node
uses for process.exit
.
Argument type of System.addressOf
This function is declared as addressOf(o: any): string
, but any
is a bit imprecise here (and almost anywhere). This function will always throw on non-object types, so the correct declaration should be addressOf(o: object): string
. Keep in mind that TypeScript is aware of the difference between primitive types and their object versions (e.g. string
vs String
). You can test this in the REPL:
gjs> const System = imports.system
gjs> System.addressOf({ prop: 'value' })
"0xa283ae3d240"
gjs> System.addressOf(12)
typein:14:8 Error: Error invoking addressOf, at argument 0 (object): Not an object
@typein:14:8
@<stdin>:1:42
gjs> System.addressOf('some text')
typein:16:8 Error: Error invoking addressOf, at argument 0 (object): Not an object
@typein:16:8
@<stdin>:1:42
gjs> System.addressOf(new String('some text'))
"0x300cf08144f0"