Big changes to enonic-types imports

Major changes to import in the 0.3.0 release of enonic-types

I have moved all the types into their corresponding modules – so that they have to be imported from there, instead of from the "enonic-types" package.

Here is an example of the changes you will have to make to your code:

- import { Request, Response } from "enonic-types/controller";
- import { get } from "/lib/xp/content";
- import { Content } from "enonic-types/content";
+ import { get, Content } from "/lib/xp/content";

- export function post(req: Request): Response {
+ export function post(req: XP.Request): XP.Response {
    const content: Content = get({ 
      key: req.params.key!
    })
  
    ...
  }

As you can see I have also removed the need to import Request and Response from "enonic-types/controller", since they now exist in the global XP namespace.


These two changes together makes it so that you should never need to import from "enonic-types" directly in your code any more, as long as you have your tsconfig.json configured like this:

{
  "compilerOptions": {
    "types": ["node", "enonic-types"]
  }
}

I think this release cleans up the imports nicely.

See the release notes for a protip on how we will be doing these imports in the upcoming TypeScript 4.5 that drops next month.

– Tom

2 Likes