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

TypeScript compile fails #659

Closed
gflohr opened this issue Jun 17, 2024 · 8 comments
Closed

TypeScript compile fails #659

gflohr opened this issue Jun 17, 2024 · 8 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@gflohr
Copy link

gflohr commented Jun 17, 2024

I can no longer build a package depending on valibot version 0.32.0 or 0.31.0. Downgrading to 0.30.0 fixes the issue.

index.ts:

import * as v from 'valibot';
console.log(v.object({}));

package.json:

{
  "name": "valibot-build",
  "scripts": {
    "build": "rm -rf dist; tsc"
  },
  "dependencies": {
    "valibot": "^0.32.0"
  },
  "devDependencies": {
    "typescript": "^5.4.5"
  }
}

tsconfig.json:

{
	"compilerOptions": {
		"allowSyntheticDefaultImports": true,
		"noImplicitAny": true,
		"noImplicitReturns": true,
		"noImplicitThis": true,
		"removeComments": true,
		"declaration": true,
		"target": "ES2017",
		"lib": ["ES2017", "dom"],
		"module": "CommonJS",
		"sourceMap": true,
		"typeRoots": ["node_modules/@types"],
		"esModuleInterop": true,
		"moduleResolution": "node",
		"strictNullChecks": true,
		"strictBindCallApply": true,
		"forceConsistentCasingInFileNames": true,
		"noFallthroughCasesInSwitch": true,
		"outDir": "dist",
		"resolveJsonModule": true
	},
	"exclude": ["node_modules"],
}

I have played around with the tsconfig.json but to no avail. The build fails:

$ npm run build

> build
> rm -rf dist; tsc

node_modules/valibot/dist/index.d.ts:5678:189 - error TS2344: Type 'QuestionMarkSchema' does not satisfy the constraint 'BaseSchema<unknown, unknown, BaseIssue<unknown>>'.
  Type 'LazySchema<QuestionMarkSchema>' is not assignable to type 'BaseSchema<unknown, unknown, BaseIssue<unknown>>'.
    The types returned by '_run(...)' are incompatible between these types.
      Type 'Dataset<unknown, unknown>' is not assignable to type 'Dataset<unknown, BaseIssue<unknown>>'.
        Type 'TypedDataset<unknown, unknown>' is not assignable to type 'Dataset<unknown, BaseIssue<unknown>>'.
          Type 'TypedDataset<unknown, unknown>' is not assignable to type 'TypedDataset<unknown, BaseIssue<unknown>>'.
            Type 'unknown' is not assignable to type 'BaseIssue<unknown>'.

5678 type QuestionMarkSchema = NullishSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | LazySchema<QuestionMarkSchema> | NonNullableSchema<QuestionMarkSchema, ErrorMessage<NonNullableIssue> | undefined>;
                                                                                                                                                                                                 ~~~~~~~~~~~~~~~~~~

node_modules/valibot/dist/index.d.ts:5678:229 - error TS2344: Type 'QuestionMarkSchema' does not satisfy the constraint 'BaseSchema<unknown, unknown, BaseIssue<unknown>>'.

5678 type QuestionMarkSchema = NullishSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | LazySchema<QuestionMarkSchema> | NonNullableSchema<QuestionMarkSchema, ErrorMessage<NonNullableIssue> | undefined>;
                                                                                                                                                                                                                                         ~~~~~~~~~~~~~~~~~~

node_modules/valibot/dist/index.d.ts:5682:321 - error TS2344: Type 'QuestionMarkSchema | QuestionMarkSchemaAsync' does not satisfy the constraint 'BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
  Type 'LazySchema<QuestionMarkSchema>' is not assignable to type 'BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
    Type 'LazySchema<QuestionMarkSchema>' is not assignable to type 'BaseSchema<unknown, unknown, BaseIssue<unknown>>'.

5682 type QuestionMarkSchemaAsync = NullishSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | LazySchemaAsync<QuestionMarkSchema | QuestionMarkSchemaAsync> | NonNullableSchemaAsync<QuestionMarkSchema | QuestionMarkSchemaAsync, ErrorMessage<NonNullableIssue> | undefined>;
                                                                                                                                                                                                                                                                                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/valibot/dist/index.d.ts:5682:392 - error TS2344: Type 'QuestionMarkSchema | QuestionMarkSchemaAsync' does not satisfy the constraint 'BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.

5682 type QuestionMarkSchemaAsync = NullishSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | LazySchemaAsync<QuestionMarkSchema | QuestionMarkSchemaAsync> | NonNullableSchemaAsync<QuestionMarkSchema | QuestionMarkSchemaAsync, ErrorMessage<NonNullableIssue> | undefined>;
                                                                                                                                                                                                                                                                                                                                                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/valibot/dist/index.d.ts:6200:48 - error TS2344: Type 'TItems[TKey]' does not satisfy the constraint 'BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
  Type 'TItems[Exclude<keyof TItems, keyof []>]' is not assignable to type 'BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
    Type 'TItems[string] | TItems[symbol]' is not assignable to type 'BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
      Type 'TItems[string]' is not assignable to type 'BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
        Type 'TItems[string]' is not assignable to type 'BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
          Type 'TItems[Exclude<keyof TItems, keyof []>]' is not assignable to type 'BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
            Type 'TItems[TKey]' is not assignable to type 'BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
              Type 'TItems[Exclude<keyof TItems, keyof []>]' is not assignable to type 'BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
                Type 'TItems[string] | TItems[symbol]' is not assignable to type 'BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.
                  Type 'TItems[string]' is not assignable to type 'BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>'.

6200     [TKey in TupleKeys<TItems>]: DotPath<TKey, TItems[TKey]>;
                                                    ~~~~~~~~~~~~


Found 5 errors in the same file, starting at: node_modules/valibot/dist/index.d.ts:5678
@fabian-hiller
Copy link
Owner

Does the skipLibCheck option solves the problem? https://www.typescriptlang.org/tsconfig/#skipLibCheck

@fabian-hiller fabian-hiller self-assigned this Jun 17, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Jun 17, 2024
@gflohr
Copy link
Author

gflohr commented Jun 17, 2024

Yes, setting skipLibCheck to true resolves the issue for me, thank you! Feel free to close the issue.

gflohr added a commit to gflohr/esgettext that referenced this issue Jun 17, 2024
@fabian-hiller fabian-hiller added documentation Improvements or additions to documentation and removed question Further information is requested labels Jun 17, 2024
@fabian-hiller
Copy link
Owner

I will add it to our docs first! Thanks for bringing this up!

@threehams
Copy link

Adding skipLibCheck isn't really a fix, since it skips checking on all .d.ts files across the whole project. This can result in any leaking out, since they are legitimate errors.

does not satisfy the constraint errors are usually pretty simple to fix, I can take a look now.

@fabian-hiller
Copy link
Owner

Feel free to have a look. 🙌

@carcinocron
Copy link

carcinocron commented Jul 2, 2024

just use skipLibCheck

that would be like if zod devs responded to "Why is zod 100kb" with "just use gzip".

I'm currently using tsc-silent, to work around this issue, here's my current hall of shame.

tsc-silent -p ./tsconfig.json --suppress @/node_modules/solid-start/ --suppress @/node_modules/@rollup/ --suppress @/node_modules/valibot/dist/index.d.ts

@fabian-hiller
Copy link
Owner

This will probably be fixed in the next version.

@fabian-hiller
Copy link
Owner

v0.38.0 is available 🚀

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

Successfully merging a pull request may close this issue.

4 participants