Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not make the source type of a vector layer generic #15831

Merged
merged 2 commits into from
May 16, 2024

Conversation

ahocevar
Copy link
Member

@ahocevar ahocevar commented May 16, 2024

Fixes #15830.

This pull request changes the TypeScript signature of ol/layer/Vector, ol/layer/VectorImage and ol/layer/Heatmap to accept the feature type instead of the source type as type parameter. This change makes sense because the previous signature was redundant, and did not work in some cases (see #15830).

Example: Previously, we had:

const layer: VectorLayer<VectorSource<Feature<Point>>> = new VectorLayer({
  source: new VectorSource({ // no other type accepted by VectorLayer
    features: [
      new Feature(new Point([0, 0]))
    ]
  })
});

And now we have:

const layer: VectorLayer<Feature<Point>> = new VectorLayer({
  source: new VectorSource({
    features: [
      new Feature(new Point([0, 0]))
    ]
  })
});

Copy link

📦 Preview the website for this branch here: https://deploy-preview-15831--ol-site.netlify.app/.

@ahocevar
Copy link
Member Author

ahocevar commented May 16, 2024

Added another commit to also fix the mentioned issue with Cluster sources.

Copy link
Member

@tschaub tschaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ahocevar

@ahocevar ahocevar merged commit 8658a1d into openlayers:main May 16, 2024
8 checks passed
@ahocevar ahocevar deleted the vector-layer-generics branch May 16, 2024 14:07
@MarcelCoding
Copy link

MarcelCoding commented May 19, 2024

I think there are now some broken internal typings in node_modules/.pnpm/ol@9.2.2/node_modules/ol/layer/VectorImage.d.ts:

1. Type 'VectorSource<FeatureType>' does not satisfy the constraint 'VectorSource<FeatureLike> | VectorTile<FeatureLike>'.
     Type 'VectorSource<FeatureType>' is not assignable to type 'VectorSource<FeatureLike>'.
       Types of property 'setLoader' are incompatible.
         Type '(loader: FeatureLoader<FeatureType>) => void' is not assignable to type '(loader: FeatureLoader<FeatureLike>) => void'.
           Types of parameters 'loader' and 'loader' are incompatible.
             Types of parameters 'arg4' and 'arg4' are incompatible.
               Type '((arg0: FeatureType[]) => void) | undefined' is not assignable to type '((arg0: FeatureLike[]) => void) | undefined'.
                 Type '(arg0: FeatureType[]) => void' is not assignable to type '(arg0: FeatureLike[]) => void'.
                   Types of parameters 'arg0' and 'arg0' are incompatible.
                     Type 'FeatureLike[]' is not assignable to type 'FeatureType[]'.
                       Type 'FeatureLike' is not assignable to type 'FeatureType'.
                         'FeatureType' could be instantiated with an arbitrary type which could be unrelated to 'FeatureLike'. [2344]

image

Output of the build of my application: All errors are in openlayers:

❯ pnpm run build

> kindergarten@0.0.0 build /home/marcel/workspace/tlms/kindergarten
> ng build --output-path ./dist

Application bundle generation failed. [7.547 seconds]

✘ [ERROR] TS2344: Type 'VectorSource<FeatureType>' does not satisfy the constraint 'VectorSource<FeatureLike> | VectorTile<FeatureLike>'.
  Type 'VectorSource<FeatureType>' is not assignable to type 'VectorSource<FeatureLike>'.
    Types of property 'setLoader' are incompatible.
      Type '(loader: FeatureLoader<FeatureType>) => void' is not assignable to type '(loader: FeatureLoader<FeatureLike>) => void'.
        Types of parameters 'loader' and 'loader' are incompatible.
          Types of parameters 'arg4' and 'arg4' are incompatible.
            Type '((arg0: FeatureType[]) => void) | undefined' is not assignable to type '((arg0: FeatureLike[]) => void) | undefined'.
              Type '(arg0: FeatureType[]) => void' is not assignable to type '(arg0: FeatureLike[]) => void'.
                Types of parameters 'arg0' and 'arg0' are incompatible.
                  Type 'FeatureLike[]' is not assignable to type 'FeatureType[]'.
                    Type 'FeatureLike' is not assignable to type 'FeatureType'.
                      'FeatureLike' is assignable to the constraint of type 'FeatureType', but 'FeatureType' could be instantiated with a different subtype of constraint 'FeatureLike'.
                        Type 'Feature<Geometry>' is not assignable to type 'FeatureType'.
                          'Feature<Geometry>' is assignable to the constraint of type 'FeatureType', but 'FeatureType' could be instantiated with a different subtype of constraint 'FeatureLike'. [plugin angular-compiler]

    node_modules/.pnpm/ol@9.2.2/node_modules/ol/layer/Vector.d.ts:172:107:
      172 │ ...ctorLayer<import("../source/Vector.js").default<FeatureType>, ...
          ╵              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] TS2344: Type 'VectorSource<FeatureType>' does not satisfy the constraint 'VectorSource<FeatureLike> | VectorTile<FeatureLike>'.
  Type 'VectorSource<FeatureType>' is not assignable to type 'VectorSource<FeatureLike>'.
    Types of property 'setLoader' are incompatible.
      Type '(loader: FeatureLoader<FeatureType>) => void' is not assignable to type '(loader: FeatureLoader<FeatureLike>) => void'.
        Types of parameters 'loader' and 'loader' are incompatible.
          Types of parameters 'arg4' and 'arg4' are incompatible.
            Type '((arg0: FeatureType[]) => void) | undefined' is not assignable to type '((arg0: FeatureLike[]) => void) | undefined'.
              Type '(arg0: FeatureType[]) => void' is not assignable to type '(arg0: FeatureLike[]) => void'.
                Types of parameters 'arg0' and 'arg0' are incompatible.
                  Type 'FeatureLike[]' is not assignable to type 'FeatureType[]'.
                    Type 'FeatureLike' is not assignable to type 'FeatureType'.
                      'FeatureType' could be instantiated with an arbitrary type which could be unrelated to 'FeatureLike'. [plugin angular-compiler]

    node_modules/.pnpm/ol@9.2.2/node_modules/ol/layer/VectorImage.d.ts:161:139:
      161 │ ...ctorLayer<import("../source/Vector.js").default<FeatureType>, ...
          ╵              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] TS2344: Type 'VectorSource<FeatureType>' does not satisfy the constraint 'VectorSource<Feature<Geometry>>'.
  Types of property 'setLoader' are incompatible.
    Type '(loader: FeatureLoader<FeatureType>) => void' is not assignable to type '(loader: FeatureLoader<Feature<Geometry>>) => void'.
      Types of parameters 'loader' and 'loader' are incompatible.
        Types of parameters 'arg4' and 'arg4' are incompatible.
          Type '((arg0: FeatureType[]) => void) | undefined' is not assignable to type '((arg0: Feature<Geometry>[]) => void) | undefined'.
            Type '(arg0: FeatureType[]) => void' is not assignable to type '(arg0: Feature<Geometry>[]) => void'.
              Types of parameters 'arg0' and 'arg0' are incompatible.
                Type 'Feature<Geometry>[]' is not assignable to type 'FeatureType[]'.
                  Type 'Feature<Geometry>' is not assignable to type 'FeatureType'.
                    'Feature<Geometry>' is assignable to the constraint of type 'FeatureType', but 'FeatureType' could be instantiated with a different subtype of constraint 'Feature<Geometry>'. [plugin angular-compiler]

    node_modules/.pnpm/ol@9.2.2/node_modules/ol/layer/VectorImage.d.ts:165:34:
      165 │ ...: Options<import("../source/Vector.js").default<FeatureType>> ...
          ╵              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


 ELIFECYCLE  Command failed with exit code 1.
 
 ```

@ahocevar
Copy link
Member Author

@MarcelCoding Have you tried v9.2.2?

@MarcelCoding
Copy link

Yeah, sorry for not explicitly mentioned it, take a look at my node modules path. Also this worked before I've updated.

@ahocevar
Copy link
Member Author

@MarcelCoding I cannot reproduce. Can you share a reproduction repository, or at least your tsconfig.json?

@MarcelCoding
Copy link

Sorry, I just tested where it went wrong, And it started going wrong with v9.2.0. v9.1.0 is the last version which is working. I'll create an Issue, as it is unrelated to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type VectorSource<Feature<Geometry>> is not assignable to type VectorSource<FeatureLike>
3 participants