Search code examples
javascripttypescript

Are there no limits to Javascript/Typescript file extensions?


I see people using extensions like .d.ts, .schema.ts, .route.ts, routes.ts and basically anything and everything, so I was wondering if there is no limit to the extensions you can give to your files in typescript/javascript (I've seen people do this with javascript too). So someone kindly explain what are these extensions and how to use them.

Thank you.

Edits for clarification:
In web development projects, especially when they use typescript for development, sometimes the devs use filenames that end with seemingly arbitrary extensions. Some common file extensions that I've seen are filename.d.ts, filename.route.ts, filename.actions.ts etc. Coming from a development environment where file extensions play a major role in how a sepcific file behaves (Python, Java and C), this made me very confused and I couldn't figure out:

  1. If there was a limit to the extensions that we can give to a file name, or only a defined set of extensions are available?
  2. Does the extensions change how the file behaves or how the file is processed by the compiler/engine? If so, please give me some examples so I can understand or link some sources for me to learn from.

Solution

  • The extension of a file is always the portion after the rightmost dot.

    Hence, the extension of all the files you mention is .ts. We can add as many dots in the middle of a file name as we want, only the last one matters for the extension.