andreasbm/lit-translate

Error when using simple config

dflorey opened this issue · 1 comments

I'm struggling with the following error. Can you help?
The fetch()-loader works just fine, but how to I return a static config for testing?
Any help would be appreciated... Thx!

registerTranslateConfig({
  loader: lang => {
    switch (lang) {
      case "en":
        return {
          photos: `You have {numPhotos, plural, =0 {no photos.} =1 {one photo.} other {# photos.}}`
        };
    }
  }
});
TS2322: Type '(lang: string) => { photos: string; } | undefined' is not assignable to type 'StringsLoader'.
  Type '{ photos: string; } | undefined' is not assignable to type 'Promise<Strings>'.
    Type 'undefined' is not assignable to type 'Promise<Strings>'.

I have no clue what I'm doing, but this seems to work:

registerTranslateConfig({
  loader: lang => {
    return new Promise<Strings>((resolve, reject) => {
      resolve(
        {
          "header": {
            "title": "Hello",
            "subtitle": "World"
          },
          "cta": {
            "awesome": "things are awesome!",
            "cats": "Cats"
          }
        });
    });
  }
});