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

[0916-0922]日志 #46

Open
jx453331958 opened this issue Sep 29, 2019 · 0 comments
Open

[0916-0922]日志 #46

jx453331958 opened this issue Sep 29, 2019 · 0 comments
Labels

Comments

@jx453331958
Copy link
Owner

Typescript: absolute->relative module path transformation

https://stackoverflow.com/questions/52500365/typescript-declaration-file-created-with-alias-instead-of-relative-path
FredKSchott/pika-pack-builders#5
https://babeljs.io/setup#installation
https://www.typescriptlang.org/docs/handbook/module-resolution.html
microsoft/TypeScript#15479
https://babeljs.io/docs/en/babel-preset-typescript
https://github.com/Microsoft/TypeScript-Babel-Starter
nestjs/nest#986
https://github.com/cevek/ttypescript/
LeDDGroup/typescript-transform-paths#4

  1. use ttypescript: https://github.com/cevek/ttypescript/
  2. use typescript-transform-paths: https://github.com/LeDDGroup/typescript-transform-paths#readme

npm config

save-exact=true 锁死版本


About “*.d.ts” in TypeScript

The "d.ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using something like jQuery or underscore, an existing javascript library. You want to consume those from your typescript code.

Rather than rewriting jquery or underscore or whatever in typescript, you can instead write the d.ts file, which contains only the type annotations. Then from your typescript code you get the typescript benefits of static type checking while still using a pure JS library.


What is the difference between *.d.ts vs *.ts in typescript?

TypeScript definition file (*.d.ts)

These files are used for describing the "shape" of a JavaScript file for use in TypeScript.

For example, say I have the following JavaScript (Example.js):

function displayMessage(message) {
    alert(message);
}

With this file alone, my TypeScript code won't have any clue this function exists. It won't know its name and it won't know its parameters. We can fix this by describing it in a definition file as such (Example.d.ts):

declare function displayMessage(message: string);

Now I can use the function displayMessage in TypeScript without compile errors and I'll get compile errors when I use it incorrectly (for example, if I supplied 2 arguments instead of 1 I would get an error).

In short: Definition files allow you to use existing JavaScript code in TypeScript without having to rewrite the code in TypeScript.

TypeScript file (.ts)

This is the standard file extension you use when writing TypeScript. It will be compiled to JavaScript.


TypeScript: *.ts and *d.ts extensions


How do I use namespaces with TypeScript external modules?


declare namespace

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

No branches or pull requests

1 participant