Reputation: 382
I want ask one question. I am creating something like game on pure typescript (for studying purpose). I want imply something like Database to this project (if u have better idea for me, after reading this, say it :) I create export class with name database, and here i set static variable "test", for example:
export class Database {
static test = {
1: {
firstName : 'testovaci',
secondName : 'test'
}
};
constructor() {
}
}
This export class are importing in main.ts, and in main.ts i have something like this (only for testing):
// imports
import { Database } from './js/database/database'
//test db
Database.test[1].firstName = 'tesst';
Database.test[2] = {};
Database.test[2].firstName = 'tesst';
console.log(Database.test[1]);
console.log(Database.test[2]);
But when I add to object test new object (Database.test[2] = {};), it works, but compiler said ERROR (Element implicitly has an 'any' type because type '{ 1: { firstName: string; secondName: string; }; }' has no index signature.)..(this same error for all Database.test[2] / but in browser it works)
Can someone help me with this, or say me best practise, or some advice to use in typescript something like globla database (I need add, remove, etc,.. and objects with another objects which number (my id), was my first idea.
Upvotes: 1
Views: 466
Reputation: 506
As for error:
static test: any = {
// your code
};
Or you can create interface for it and use it:
static test: myInterface = {}
As for DB - take a look to Google Firebase
Upvotes: 1