You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{defineBookFactory,defineAuthorFactory,dynamic,}from'../__generated__/fabbrica';import{test,expect,expectTypeOf}from'vitest';// Define factoriesconstBookFactory=defineBookFactory({defaultFields: {__typename: 'Book',id: dynamic(({ seq })=>`Book-${seq}`),title: 'Yuyushiki',author: undefined,},});constAuthorFactory=defineAuthorFactory({defaultFields: {__typename: 'Author',id: dynamic(({ seq })=>`Author-${seq}`),name: 'Komata Mikami',books: undefined,},traits: {withoutBooks: {defaultFields: {books: [],},},},});test('throw a compile error when an unknown trait name is passed to `.use()`',async()=>{// @ts-expect-error -- Should throw a compile error, but does not throw.awaitBookFactory.use('unknownTrantName').build();// @ts-expect-errorawaitAuthorFactory.use('unknownTrantName').build();});
$ npm start
> start
> npm run gen && npm run lint && npm run test
> gen
> graphql-codegen✔ Parse Configuration✔ Generate outputs
> lint
> tscsrc/index.test.ts:34:3 - error TS2578: Unused '@ts-expect-error' directive.34 // @ts-expect-error -- Should throw a compile error, but does not throw. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Found 1 error in src/index.test.ts:34npm ERR! code EIOnpm ERR! syscall writenpm ERR! errno -5npm ERR! EIO: i/o error, writenpm ERR! A complete log of this run can be found in: /home/.npm/_logs/2024-03-09T05_46_36_334Z-debug-0.logjsh: spawn npm EIO
The text was updated successfully, but these errors were encountered:
mizdra
changed the title
No type error is reported when an invalid trait name is passed to use
No type error is reported when an unknown trait name is passed to use
Mar 9, 2024
This problem occurs with factories where no traits are defined.
https://stackblitz.com/edit/playground-graphql-codegen-typescript-fabbrica-1ryp1f?file=src%2Findex.test.ts&view=editor
The text was updated successfully, but these errors were encountered: