-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Bug Description
When a variable is passed as a shorthand property in an object literal, and the variable name matches the target type's property name, SCIP resolves the occurrence to the type definition's property (external symbol) instead of the local variable (local symbol).
This only occurs with shorthand syntax. Using explicit key: value syntax correctly emits both the external key reference and the local variable reference.
Reproduction
import { ApolloServer } from '@apollo/server';
const resolvers = {
Query: {
books: () => books,
book(_: unknown, args: { id: number }) {
return books[args.id];
},
},
Mutation: {
async addBook(_: unknown, args: { title: string; author: string }) {
const newBook = { title: args.title, author: args.author };
books.push(newBook);
return newBook;
},
},
};
// Bug: `resolvers` resolves to ApolloServerOptions#resolvers (external)
// instead of the local `const resolvers` above
const server = new ApolloServer({ typeDefs, resolvers });Steps to reproduce
- Index the project with
scip-typescript - Inspect the SCIP index - find the occurrence for
resolversinsidenew ApolloServer({ typeDefs, resolvers }) - The symbol points to
ApolloServerOptions#resolvers(the type definition's property), not the localconst resolvers
Confirmation
Confirmed by modifying the code and re-indexing:
| Scenario | Result |
|---|---|
new ApolloServer({ typeDefs, resolvers }) - shorthand, name matches parameter |
Incorrect - resolves to external type properties only, no local variable reference emitted |
new ApolloServer({ typeDefs, resolvers: resolvers }) - explicit key-value, same name |
Correct - key emits external type refs, value emits local resolvers. reference |
Rename to resolvers1 + new ApolloServer({ typeDefs, resolvers1 }) |
Correct - no name collision, local variable resolved properly |
SCIP index evidence
With explicit resolvers: resolvers at the constructor line:
# Key "resolvers" - external type property refs:
ApolloServerOptionsWithGateway#resolvers
ApolloServerOptionsWithSchema#resolvers
ApolloServerOptionsWithTypeDefs#resolvers
# Value "resolvers" - local variable ref:
src/index.ts/resolvers.
With shorthand { resolvers }, only the external type property refs are present - the local variable reference is missing entirely.
Expected behavior
Shorthand { resolvers } should produce the same occurrences as explicit resolvers: resolvers - both the external type property refs and the local variable ref.
Environment
scip-typescriptv0.3.15- TypeScript 5.6.2
Possibly related
- Incorrect symbol resolution for property shorthand in decorators (e.g. { imports } in NestJS modules) #415 - reports a similar symptom in NestJS decorator context (
@Module({ imports })resolves toModuleMetadata#importsinstead of localimportsvariable). May share the same underlying cause in howShorthandPropertyAssignmentAST nodes are indexed.