@wearesage/schema
Version:
A flexible schema definition and validation system for TypeScript with multi-database support
77 lines (63 loc) • 2.67 kB
text/typescript
// Simple test to see what dynamic imports return
class SimpleClass {
// Don't override name, it's read-only
}
// Test 1: Direct reference
console.log('=== Direct reference ===');
const directRef = SimpleClass;
console.log('Direct:', directRef);
console.log('Type:', typeof directRef);
console.log('Name:', directRef.name);
console.log('Is Promise?:', directRef instanceof Promise);
// Test 2: Function that returns direct reference
console.log('\n=== Function returning direct reference ===');
function getDirectRef() {
return SimpleClass;
}
const funcResult = getDirectRef();
console.log('Function result:', funcResult);
console.log('Type:', typeof funcResult);
console.log('Name:', funcResult.name);
console.log('Is Promise?:', funcResult instanceof Promise);
// Test 3: What our decorator actually does - but with a twist
console.log('\n=== Testing syntax like our decorators ===');
// This is what we have in Space.ts:
// target: () => import('./User').User
// But import('./User').User is NOT a dynamic import call
// It's trying to access the .User property of an import statement
// Let's see what that actually means:
// The correct dynamic import would be:
// target: async () => (await import('./User')).User
try {
// This simulates what our decorator syntax actually tries to do:
// It's trying to access a property .User on the import() call itself
// which doesn't exist and would be undefined or throw an error
console.log('Testing: import("./non-existent").User');
// This would be: import('./User').User
// Which is trying to access .User property on a Promise
const importCall = import('./non-existent-file');
console.log('Import call result:', importCall);
console.log('Import call type:', typeof importCall);
console.log('Import call is Promise?:', importCall instanceof Promise);
// Now try to access .User property on it (this is what our code does)
console.log('Trying to access .User on the import Promise...');
const userAccess = (importCall as any).User;
console.log('Result of importCall.User:', userAccess);
console.log('Type of importCall.User:', typeof userAccess);
} catch (error) {
console.log('Error:', error.message);
}
console.log('\n=== What the syntax SHOULD be ===');
// This is what it SHOULD be for proper dynamic imports:
async function properDynamicImport() {
try {
const module = await import('./test-entities/User');
return module.User;
} catch (error) {
console.log('Proper dynamic import failed (expected):', error.message);
return null;
}
}
properDynamicImport().then(result => {
console.log('Proper dynamic import result:', result);
});