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

Improve build-time error message when .telefunc.js export isn't a function #142

Open
brillout opened this issue Jan 31, 2025 · 0 comments
Open

Comments

@brillout
Copy link
Owner

When an export isn't a function then the error message is a bit ugly at build-time:

 ~/code/telefunc/examples/vite (brillout/dev*|u+2) pnpm run build

> @ build /home/rom/code/telefunc/examples/vite
> vite build && vite build --ssr

vite v4.3.9 building for production...
✓ 30 modules transformed.
dist/client/index.html                0.15 kB │ gzip: 0.14 kB
dist/client/assets/index-0ace5282.js  8.95 kB │ gzip: 3.69 kB
✓ built in 236ms
vite v4.3.9 building SSR bundle for production...
✓ 3 modules transformed.
dist/server/package.json                       0.02 kB
dist/server/assets/hello.telefunc-d5e7aa62.js  0.61 kB
dist/server/entry.js                           0.62 kB
telefunc v0.1.84 shield() generation
✓ shield() generated for the telefunctions hello() (hello.telefunc.ts)
TypeScript project /home/rom/code/telefunc/examples/vite/tsconfig.json errors:
__telefunc_shieldGen_hello.telefunc.ts:5:60 - error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.

5 type someNonFunctionExportShield = ShieldArrStr<Parameters<typeof someNonFunctionExport>>;
                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hello.telefunc.ts:14:24 - error TS2345: Argument of type '({ name }: { name: string; }) => Promise<{ message: string; }>' is not assignable to parameter of type 'Telefunction'.
  Types of parameters '__0' and 'args' are incompatible.
    Type 'unknown' is not assignable to type '{ name: string; }'.

14 __decorateTelefunction(someFunc, "hello", "/hello.telefunc.ts", "/home/rom/code/telefunc/examples/vite", true);
                          ~~~~~~~~
hello.telefunc.ts:15:24 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'Telefunction'.

15 __decorateTelefunction(someNonFunctionExport, "someNonFunctionExport", "/hello.telefunc.ts", "/home/rom/code/telefunc/examples/vite", true);
                          ~~~~~~~~~~~~~~~~~~~~~
../../node_modules/.pnpm/@[email protected]/node_modules/@types/mdx/index.d.ts:66:58 - error TS2503: Cannot find namespace 'JSX'.

66     export default function MDXContent(props: MDXProps): JSX.Element;
                                                            ~~~
../../node_modules/.pnpm/@[email protected]/node_modules/@types/mdx/types.d.ts:4:51 - error TS2503: Cannot find namespace 'JSX'.

4 type FunctionComponent<Props> = (props: Props) => JSX.Element;
                                                    ~~~
../../node_modules/.pnpm/@[email protected]/node_modules/@types/mdx/types.d.ts:6:52 - error TS2503: Cannot find namespace 'JSX'.

6 type ClassComponent<Props> = new (props: Props) => JSX.ElementClass;
                                                     ~~~
../../node_modules/.pnpm/@[email protected]/node_modules/@types/mdx/types.d.ts:11:65 - error TS2503: Cannot find namespace 'JSX'.

11     [key: string]: NestedMDXComponents | Component<any> | keyof JSX.IntrinsicElements;
                                                                   ~~~
../../node_modules/.pnpm/@[email protected]/node_modules/@types/mdx/types.d.ts:23:23 - error TS2503: Cannot find namespace 'JSX'.

23         [Key in keyof JSX.IntrinsicElements]?: Component<JSX.IntrinsicElements[Key]> | keyof JSX.IntrinsicElements;
                         ~~~
../../node_modules/.pnpm/@[email protected]/node_modules/@types/mdx/types.d.ts:23:58 - error TS2503: Cannot find namespace 'JSX'.

23         [Key in keyof JSX.IntrinsicElements]?: Component<JSX.IntrinsicElements[Key]> | keyof JSX.IntrinsicElements;
                                                            ~~~
../../node_modules/.pnpm/@[email protected]/node_modules/@types/mdx/types.d.ts:23:94 - error TS2503: Cannot find namespace 'JSX'.

23         [Key in keyof JSX.IntrinsicElements]?: Component<JSX.IntrinsicElements[Key]> | keyof JSX.IntrinsicElements;
                                                                                                ~~~
../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/index.d.ts:784:22 - error TS2420: Class 'import("/home/rom/code/telefunc/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/index").FSWatcher' incorrectly implements interface 'import("fs").FSWatcher'.
  Type 'FSWatcher' is missing the following properties from type 'FSWatcher': ref, unref

784 export declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
                         ~~~~~~~~~

[[email protected]][Warning] Failed to generate shield() for telefunction someNonFunctionExport() (hello.telefunc.ts). TypeScript errors (printed above) can be problematic for shield() generation. Fix your TypeScript errors and try again. See https://telefunc.com/shield#typescript-automatic for more information.
✓ built in 6.72s

We could use ts-morph to check whether all exports are functions but it isn't trivial. The code removed here which did that wasn't exhaustive as attested by the failing CI of this change. See also: #141.

@brillout brillout changed the title polish error message Improve build-time error message when .telefunc.js export isn't a function Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant