loreanvictor / tyfon

typed functions over network
https://loreanvictor.github.io/tyfon
MIT License
37 stars 4 forks source link

Updates in external functions signatures does not register properly #14

Closed must closed 3 years ago

must commented 3 years ago

When updating the backend API's signature to make a property optional it can result in an error on the frontend where the SDK package is out of date (i.e. property not marked as optional) hence resulting in a typescript error.

Further testing is required.

loreanvictor commented 3 years ago

Couldn't reproduce. Steps that I followed:

  1. I setup a sample server and client.
  2. I ran everything to ensure everything works
  3. I modified server code like this:
    export const getMessage = async (user: User, greetings?: string) => `${greetings || 'Hellow'} ${user.name}!`;
  4. I rebuilt and re-ran the server, and re-installed client SDK:
    # on the server side code
    tyfon b
    tyfon s
    # on the client side code
    tyfon i

    Signatures are updated instantly. Code works fine.

  5. I changed the server code to this:
    export const getMessage = async (user: User, greetings: string) => `${greetings || 'Hellow'} ${user.name}!`;
  6. Rebuilt and re-ran server, re-installed client SDK. Client has now errors (correctly).
  7. Reverted server code to optional greetings argument. Rebuilt and reran, re-installed SDK. Everything fine.

@must Am I missing something?

must commented 3 years ago

So I figured that this works only if the client is restarted on my end after re-installing the SDK tyfon i. If the client is kept running (even when running tyron i on the side), it just results in the types not being updated.

loreanvictor commented 3 years ago

well unless your client run-time reloads, there is no way for newly installed type definitions to be loaded. since the client-side runtime is independent of TyFON, this is not an issue with TyFON. I recommend configuring your client-side runtime so that it reloads on changes to node_modules/@api (typically node_modules is ignored by client runtimes such as webpack dev server).

must commented 3 years ago

Just for future reference. You can easily exclude the folder in the webpack config file:

module: {
    rules: [
      {
        // ...
        exclude: /node_modules\/(?!(\@api)\/).*/,
      }
    ]
  },
loreanvictor commented 3 years ago

Just for future reference. You can easily exclude the folder in the webpack config file:


module: {

    rules: [

      {

        // ...

        exclude: /node_modules\/(?!(\@api)\/).*/,

      }

    ]

  },

will add this to the docs, perfect (also would appreciate a PR adding this to the docs)