How to see the implementation of the Typescript code?

Asked

Viewed 97 times

7

In several programming languages that I have worked or currently work with, I can see the implementation of the developed codes.

In Dart or Java for example, I can go to the source code and analyze the implementation and, thus, I can take my action before that a certain method, this is true for libs or for the core.

In Typescript, I only have one interface, and often I can’t see the implementation underneath the scenes. If this stop is open source, why doesn’t it display? If possible, how do you display this?

2 answers

7


Typescript is a language that runs on top of Javascript. At least she was designed for this, nothing prevents her one day to change course, but the goal is to continue like this. She uses a technique called transpilation where the compiler reads the code in TS and writes another in JS. The code in TS does not need to be distributed anywhere. The JS code is distributed and this is the one you can see. Unless whoever wrote the TS code provides you directly.

If you are looking for the sources of the TS library then it has at least nothing substantial, it uses the JS library. If you want the compiler sources you have in https://github.com/microsoft/TypeScript. Ali has something library, basically to establish contracts what already exists in JS.

If what you’re talking about interface is precisely that this library published there only has these statements and not the implementation of the code of these interfaces so it has nothing to show because it has not implemented anything (or almost nothing), is what I said is already all ready in the JS library. What are you seeing in these files .d.ts is just a way to create contracts for what already exists and to be able to use in your code according to the rules of the language. Since in JS there is no contract, there are no interfaces and types, and TS does, so the only thing TS has to add is the contract to everything, so it creates the interfaces and tells you which types a function accepts.

Interfaces need to be implemented to use, but they are already in JS, do not have to do again, would only bring problems try to do it again.

The goal of Typescript is basically to create contracts for Javascript and give more robustness and allow larger and more complex code bases than can be done in JS.

Most libraries available for JS have the same feature of creating contracts for use in statically typed form (although this term does not look good in this type of language, because it has a bark like this, but in the end it will generate something that has the same performance problem of dynamic typing, and nothing prevents that at another point the robustness is circumvented). The place that centralizes this is the Definitelytyped. There are contracts, implementations are in libs written in JS without the contract part which is a feature that JS does not have.

1

If the library (lib) you are using was written in Typescript, you can read its source code the same way you would with Java: accessing the repository of that library (if it is open-source or if you have access).

However, Typescript can use any library written in Javascript or compiled for Javascript, even those not written in Typescript. In such cases, interfaces are created to facilitate their use with Typescript, either by the library’s own creator or by some project contributor Definitelytyped. So there is no typescript source code to read, only Javascript.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.