I am struggling to define interface
| type
within a TypeScript class. Here is the code snippet:
class MyClass {
interface IClass {
name: string,
id: string
}
}
However, I keep encountering this error:
Unexpected token. A constructor, method, accessor, or property was expected.
My Desired Outcome:
I am developing a framework where users can extend the base class Randoms
and override certain methods, but the child class does not provide any type intelligence.
Here is an example of the issue in the code:
abstract class RandomsRoute {
public get (req:Resquest, res:Response): Promise <void> { res.send ('') }
}
// client side
import RandomsRoute, { Request, Response } from '@my-pkg'
class Client extends RandomsRoute {
// public get (req, res) {res.send('client side')} // error here
public get (req: Request, res: Response): Promise <void> { res.send ('') }
}
The problematic part seems to be:
{ Request, Response } from '@my-pkg'
I hope to simplify the import process for users and potentially offer better APIs. Any suggestions on how to achieve this?