I'm a TypeScript newb trying to write a Node.js (Node.ts?) backend, and trying to go about the basics of setting up my server. I'm using ts-node version 8.6.2 and typescript version 3.7.5, and defining validation for some domain objects in the following way (in the ajv
style):
// domain_obj_1.ts:
const commonSchema = {
type: 'object',
properties: {
foo: { type: 'string' },
},
};
export class DomainObject1 {
...
// domain_obj_2.ts:
const commonSchema = {
type: 'object',
properties: {
bar: { type: 'string' },
},
};
export class DomainObject2 {
...
However, ts-node-dev
is spitting out the following error:
error TS2403: Subsequent variable declarations must have the same type.
Variable 'commonSchema' must be of type '{ type: string; properties: { foo: { type: string; }; }; }',
but here has type '{ type: string; properties: { bar: { type: string; }; }; }'.
I can only assume Typescript is detecting a collision of these separate declarations of commonSchema
, but they're not being exported so I'm not sure how that's happening.
There's a lot I don't yet understand about TS and its use in Node, but this is surprising behavior and I'm wondering if there's something obvious I'm missing.