LÖVE 2D can interact with the file system.
love.filesystem.getLastModified("file.txt");
However, there likely is a FileRegistry stopping you.
If you don't care about why it is there, opt-out by adding "ts-love/no-file-registry"
to your tsconfig's types.
{
"compilerOptions": {
"types": [
"ts-love",
"ts-love/no-file-registry"
]
}
}
But if you want to keep it, you'll get...
- File path autocompletion.
- No missing path runtime errors.
- File metadata with no overhead code.
- Other registries contribute to this one.
How do you use it? Make a FileRegistry.d.ts file and put your available file paths within it.
interface FileRegistry {
"files/file.txt": any;
}
Now when trying to access something from the file system, only the options in this registry are allowed.
TypeScript won't let any other file path be used and will inform you at compile time or even in your editor that a file path doesn't exist.
The overhead being you'll have to make sure this registry stays up to date. This could be done via a .sh
script.
Hell you can even give the file metadata.
interface FileRegistry {
"files/file.json": { type: "json" };
}
If you've good with your typings you can disallow json files from being used in the wrong context.