crazyfactory/tslint-rules

Unknown Node Type error when putting call signatures in interface

Opened this issue · 3 comments

The 'interface-sort-keys' rule threw an error in '/home/ubuntu/app/src/lib/client/apollo/dataIdFromObject.ts':
Error: 
          Unknown Node Type!
          This might be a case that's not covered yet.
          Please file an issue at https://github.com/crazyfactory/tslint-rules
        
    at InterfaceSortKeysRule.checkAlphabetical (/home/ubuntu/app/node_modules/@crazyfactory/tslint-rules/lib/interfaceSortKeysRule.js:50:23)
    at InterfaceSortKeysRule.visitInterfaceDeclaration (/home/ubuntu/app/node_modules/@crazyfactory/tslint-rules/lib/interfaceSortKeysRule.js:32:14)
    at InterfaceSortKeysRule.SyntaxWalker.visitNode (/home/ubuntu/app/node_modules/tslint/lib/language/walker/syntaxWalker.js:401:22)
    at /home/ubuntu/app/node_modules/tslint/lib/language/walker/syntaxWalker.js:535:63
    at visitNodes (/home/ubuntu/app/node_modules/typescript/lib/typescript.js:18440:30)
    at Object.forEachChild (/home/ubuntu/app/node_modules/typescript/lib/typescript.js:18673:24)
    at InterfaceSortKeysRule.SyntaxWalker.walkChildren (/home/ubuntu/app/node_modules/tslint/lib/language/walker/syntaxWalker.js:535:12)
    at InterfaceSortKeysRule.SyntaxWalker.visitSourceFile (/home/ubuntu/app/node_modules/tslint/lib/language/walker/syntaxWalker.js:228:14)
    at InterfaceSortKeysRule.SyntaxWalker.visitNode (/home/ubuntu/app/node_modules/tslint/lib/language/walker/syntaxWalker.js:482:22)
    at InterfaceSortKeysRule.SyntaxWalker.walk (/home/ubuntu/app/node_modules/tslint/lib/language/walker/syntaxWalker.js:24:14)

This is the file:

interface DataIdFromObjectProps {
  __typename: string;
  _id?: string | null;
}

// with our custom resolvers
interface DataIdFromObjectType {
  (obj: { __typename: string; _id: string }): string;
  (obj: { __typename?: string | null } | { _id?: string | null }):
    | string
    | null;
  (obj: { __typename?: null } | { _id?: null }): null;
}

export const cacheObjectId = (__typename: string, _id: string) =>
  [__typename, _id].join(':');

const dataIdFromObject = (({ __typename, _id }: DataIdFromObjectProps) =>
  (__typename && _id && cacheObjectId(__typename, _id)) ||
  null) as DataIdFromObjectType;

export default dataIdFromObject;

I'm guessing it doesn't like the syntax for the call signature of the interface.

Hi @dobesv! Sorry for the delay. Thanks for your interest in the project. Too bad interface-sort-keys rule covers very limited use case. It only supports instance fields. I recommend checking out member-ordering instead. We also abandoned interface-sort-keys and have used member-ordering, have had no issues so far.

Does member-ordering work for interfaces? I thought it only works for classes.

Yes, it does work on interfaces.