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

generated types incompatible with exactOptionalPropertyTypes #13389

Open
ritschwumm opened this issue Jan 21, 2025 · 0 comments
Open

generated types incompatible with exactOptionalPropertyTypes #13389

ritschwumm opened this issue Jan 21, 2025 · 0 comments

Comments

@ritschwumm
Copy link

ritschwumm commented Jan 21, 2025

the generated types contain some contradictions which typescript does not detect due to the strict flag in the tsconfig.json being set to false.

this is a problem when a consuming project tries to enable exactOptionalPropertyTypes: now typescript considers these contradictions to be hard errors and refuses to compile.

one example are VectorTileSource and the interface ISource it implements:

ISource says "the prepare property does not have to exist, but if it exists, it has to be a function."

interface ISource extends Evented<SourceEvents> {
    ...
    readonly prepare?: () => void;
    ...
}

On the other hand VectorTileSource says "the property prepage must exists, and it has to be a value of type undefined.

export declare class VectorTileSource extends Evented<SourceEvents> implements ISource {
    ...
    prepare: undefined;
    ....
}

i'm not sure why VectorTileSource requires a prepare property to exist - if this is not strictly necessary, just removing the prepare property would solve the issue. May be confusing for a user who sets prepare and it unexpectedly does not do anything, though.

another way to solve this would be to change ISource do use readonly prepare?: () => void|undefined; which is a bit unsatisfying because now there are two different ways to express that prepare is not a function which should be called.

in general i think a typescript library should strive for the most strict typescript variant as not to limit how strict a consuming project wants to be configured.

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

No branches or pull requests

1 participant