#typify existed class

22 messages · Page 1 of 1 (latest)

polar mica
#

hi. i imported a script, it has a class inside but w/o types. i know the types, how to typify a class now?

thin sable
#

as a package?

polar mica
#

no as a script. i declare a global class like

now when im doing

const newInstance = new SomeClass()
```it has types but looks not good? dunno
thin sable
#

so you just copied over the script from somewhere?

polar mica
#

yea

thin sable
#

why not just edit the script to give it types then

polar mica
#

obfuscated

thin sable
#

i don't see how obfuscating a class would prevent you from finding the appropriate methods and typing them

polar mica
#

i just dont want to touch the script. i want to keep types away

thin sable
#

k, then use a d.ts to give types to the class within the file, not a global class

#

check out the module: class section

thin sable
#

yeah

polar mica
#

k thanks

#

ops
looks like not my case
im not importing a class like that
the script already imported with <script> tag on react page
so TS knows nothing about this
first of all i need to tell TS that this class exist in global scope and typify it

interface SomeType {
  new(): {
    // methods
  }
}

const MyClass : SomeType

works but looks ... i dont know it doesnt look good

thin sable
#

so it is in global scope?

#
declare global {
  class Foo {}
}
```you can use this then
#

hm not sure if you would need the declare global in a script d.ts

wise totem
polar mica
#

i tried this guys
but i dont have any types after this

#

also i tried implements but no affect