If you know how to fix the issue, make a pull request instead.
@types/xxxx package and had problems.Definitions by: in index.d.ts) so they can respond.If you do not mention the authors the issue will be ignored.
Is there a typing for package.json? If not, can I make one?
@andy-ms @sheetalkamat
appears that typescript defs for dayjs do not exist. Seems like an unnecessary oversight for an otherwise excellent resource.
@nukuuk ??? What I mean to discuss in this issue is about package.json file itself, not about any other packages on NPM.
@Ailrun Since package.json is a JSON spec, not a JS API, you might want to look into JSON schema instead. Specifically this is the public schema for package.json files used by IDEs and editors like VS Code: http://json.schemastore.org/package
@pluma However, we can import package.json in node.js, and we need to handle imported value.
Json schema does not give anything for TS.
That sounds like a case for something like this: https://github.com/bcherny/json-schema-to-typescript
That said, I think this is the wrong place to discuss this as package.json is not a library or environment but a JSON data format. There's no guarantee that any file called package.json is actually a package.json file (i.e. that it adheres to the spec) so you would probably want to type it explicitly on import (i.e. const packageJsonData = require("../package.json") as PackageJson).
Also ES modules don't support JSON files AFAIK so I don't think specific JSON files should be treated any different than any other files whose contents could be loaded and parsed at runtime.
@pluma We still need that PackageJson type. Package you suggest is just a creator for that PackageJson type, not a way to share it.
Yes. That's what I said. You could use that tool to generate TypeScript typings for the various existing JSON schemas. But I don't think this is a problem DefinitelyTyped is built to address.
@pluma DT is a way to share typings, isn't it? What I said from the first stage is about sharing typing of package.json.
@Ailrun try https://www.npmjs.com/package/@schemastore/package :slightly_smiling_face:
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
{
"name": "awesome",
"author": "xgqfrms",
"version": "1.0.0",
"main": "./lib/main.js",
"types": "./lib/main.d.ts"
}
{
"name": "awesome",
"author": "xgqfrms",
"version": "1.0.0",
"main": "./lib/main.js",
"typings": "./lib/main.d.ts"
}
@xgqfrms Sorry, what you suggested is nothing to do with my question.
The link explains how to add a typing of a package to package.json, yet my question is about a typing of package.json itself, not a package.
At the moment we cheated the system by adding
declare module "*.json" {
const value: any;
export default value;
}
Most helpful comment
@Ailrun try https://www.npmjs.com/package/@schemastore/package :slightly_smiling_face: