Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript source/definitions issues #104

Closed
nmocruz opened this issue Jul 14, 2018 · 7 comments
Closed

Typescript source/definitions issues #104

nmocruz opened this issue Jul 14, 2018 · 7 comments

Comments

@nmocruz
Copy link

nmocruz commented Jul 14, 2018

Hi,

I was trying to include this library in a typescript project, but maybe I'm missing something in my tsconfig.json because it starts to check source code in this module inside node_modules even excluding "node_modules". maybe is a noobie question about typescript, or it can be done something to improve here, because it tries to check ts files under node_modules/@profiscience/knockout-contrib-* using my tsconfig.json.

I'm using webpack and awesome-typescript-loader, maybe is required to do something here?

@caseyWebb
Copy link
Contributor

caseyWebb commented Jul 16, 2018

tl;dr: Add esnext.asynciterable to the lib in your tsconfig, and enable allowSyntheticDefaultImports.

Please don't close this issue. I'll do it when this is added to the documentation. I want to double check everything first before sticking it in there though.


Explanation:

So, in an ideal world, when publishing a library, you build definition files (.d.ts), and then when consumers of that library use it with tsc, it will use those to type-check their code.

I've tried to get these working in the past, but faced issues.

The first is that in order to use definitions, the types property in the package.json files for individual packages must be pointed to the built definitions. Because this is a monorepo, it leads to the problem where you have to build packages in such an order that packages that are depended on by other packages are built prior to the packages that depend on them, so that those definitions are built.

The second, even more glaring issue, is that tsc blows up when you try to build definitions for mixins, for whatever reason.

Because of this, the types property is pointed to the source code. This means, that in order for it to type check your code that is consuming this library, it must be able to parse this library. Because of certain features used (async generators, e.g. async function* myFunc() {}), you've got to tell tsc that the necessary runtime features exist.

The first issue looks like it's been resolved with TS 3.0.0, although I'm not sure how the build performance will compare; if the second issue isn't resolved though it won't really matter anyway.

@nmocruz
Copy link
Author

nmocruz commented Jul 16, 2018 via email

@nmocruz
Copy link
Author

nmocruz commented Jul 16, 2018

I forked and tried to use the typescript compile API to solve that, it still needs some work.
I'm able to generate d.ts files but I need to run ts-node excluding this d.ts as input files so they can be overwritten.
Then is needed to update packages.jon to point to index.d.ts not to index.ts

@caseyWebb
Copy link
Contributor

caseyWebb commented Jul 16, 2018

@nmocruz I'd definitely prefer to only publish type definitions, I just haven't been able to do it successfully without making the build take a loooooong time. I'm hoping project compilation w/ TS 3.0.0 will fix this.

@nmocruz
Copy link
Author

nmocruz commented Jul 16, 2018 via email

@caseyWebb
Copy link
Contributor

@nmocruz I'm under the impression this is all working? Can you review this documentation to confirm that it covers everything?

@nmocruz
Copy link
Author

nmocruz commented Aug 7, 2018

@caseyWebb I thought everything was sorted but it's the I had the transpileOnly mode actived and was hiding some errors, related with typescript. I really recommend to get a way to pusblish .d.ts files so they don't conflict with ts on the package consumer.
I tried to see the problem and a found maybe what was the bug that make your compilation fail with declaration: true. I belive that TS4094, microsoft/TypeScript#17293 I found a few and seems like is not fixed on TS 3.0.0 and if they move again as they as doing since version 2.4.1, it not be fixed soon.
I found a way to solve only private member, but it not elegant. For protected member only way is make them public or don't reuse super class implementantions.

class a {
   addItem: ()=> void;
   constructor(){
      let privateFunc = ()=>{  console.log("")  };
      this.addItem = () => {
           privateFunc();
      }
  }
}

as a said is not elegant, and we dont know if the TS4094 stuff will be fixed soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants