Currently the TypeScript declaration files are not generated even when enabled in the tsconfig.json, would be nice if this could also be generated when building.
Any updates?
Blocked by #465, no type-checking = no declarations. You can open an issue in the TypeScript plugin repo or wait for the plugin to be integrated in Parcel's core.
You can use tsc to generate type declarations independent of Parcel. Since Parcel is not doing the type-checking it's good to run tsc anyways.
Is it possible to generate type definitions for projects that use both Typescript and ReactJS? Using tsc on its own doesn't work, since the TSX needs to be parsed as well. Normally, I would use webpack, but then what would be the point of Parcel?
So, is there a way for the files to go through the normal Parcel pipeline (Babel, etc.) before going through the Typescript compiler?
It looks like the previous errors were actually just legitimate errors being emitted by the compiler. They were being suppressed by parcel.
I ended up running parcel and then running the Typescript compiler to get declaration files, as suggested by @mohsen1
Can't believe not yet implemented after 1 year and a half.
@laosb you can just run tsc for typechecking and typedefinitions...
Parcel 2 supports typechecking, not entirely sure how type definition generation in a bundler works as I've never needed that before. If I'd know how that works I would be able to implement it for Parcel 2.
any updates here?
Would be great if we could use Parcel 2 to bundle node packages and include type declarations.
This is already part of Parcel 2
This is already part of Parcel 2
I am just trying out Parcel 2. I configured my tsconfig.json to generate declarations.
Worth mentioning I am using latest nightly release of parcel with tsc transformer (parcel 2 to my big surprise uses babel typescript as a default).
Is your statement still valid?
Something like this will generate the typing at dist/types.d.ts:
{
"main": "dist/index.js"
"types": "dist/index.d.ts"
"scripts": {
"build": "parcel build src/index.js"
}
}
@mischnic you mean just having types in package.json should be enough?
I did try it tho, but am not getting it still 馃
@mischnic you mean just having types in package.json should be enough?
Yes.
I did try it tho, but am not getting it still 馃
can you open a new issue with a code sample?
can you open a new issue with a code sample?
Will do :+1:
Trying for the second time I get:
@parcel/namer-default: Target "types" declares an output file path of "dist/index.d.ts" which does not match the compiled bundle type "js".
@parcel/namer-default: Target "types" declares an output file path of "dist/index.d.ts" which does not match the compiled bundle type "js".
I have seen this being reported but wasn't able to reproduce it myself...
Seems like this is still an issue. I can reproduce this reliably on a fresh project using parcel@nightly.
If we do not have a .parcelrc file or have one that simply extends the default config adding a types entry to package.json causes the declarations to be generated.
With the following .parcelrc:
{
"extends": "@parcel/config-default",
"transformers": {
"*.{ts,tsx}": ["@parcel/transformer-babel"]
}
}
We get the error: @parcel/namer-default: Target "main" declares an output file path of "dist/index.js" which does not match the compiled bundle type "ts".
With the following .parcelrc:
{
"extends": "@parcel/config-default",
"transformers": {
"*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"]
}
}
We get the error: @parcel/namer-default: Target "types" declares an output file path of "dist/index.d.ts" which does not match the compiled bundle type "js".
"*.{ts,tsx}": ["@parcel/transformer-babel"]
You're missing @parcel/transformer-js. (And that configuration isn't needed since this is what the default config does).
Target "types" declares an output file path of "dist/index.d.ts" which does not match the compiled bundle type "js"
Please see https://github.com/parcel-bundler/parcel/issues/4666. Looking into it now...
Most helpful comment
You can use tsc to generate type declarations independent of Parcel. Since Parcel is not doing the type-checking it's good to run tsc anyways.