You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If your types are generated by your source code, publish the types with your source code. Both TypeScript and JavaScript projects can generate types via [`declaration`](/tsconfig#declaration).
Our package exposes declarations from each of those, so any user of our `browserify-typescript-extension` package needs to have these dependencies as well.
63
-
For that reason, we used `"dependencies"` and not `"devDependencies"`, because otherwise our consumers would have needed to manually install those packages.
64
-
If we had just written a command line application and not expected our package to be used as a library, we might have used `devDependencies`.
Make sure to revisit the [Consuming dependencies](/zh/docs/handbook/declaration-files/library-structures.html#consuming-dependencies)section for more information.
In the above example, if we're importing from `"package-name"`, TypeScript will try to resolve from `[...]/node_modules/package-name/ts3.1/index.d.ts` (and other relevant paths) when running in TypeScript 3.1.
119
-
If we import from `package-name/foo`, we'll try to look for `[...]/node_modules/package-name/ts3.1/foo.d.ts` and `[...]/node_modules/package-name/ts3.1/foo/index.d.ts`.
What if we're not running in TypeScript 3.1 in this example?
122
-
Well, if none of the fields in `typesVersions` get matched, TypeScript falls back to the `types` field, so here TypeScript 3.0 and earlier will be redirected to `[...]/node_modules/package-name/index.d.ts`.
When you want to only change the resolution for a single file at a time, you can tell TypeScript the file to resolve differently by passing in the exact filenames:
Note that redirections only affect the _external_API of a package; import resolution within a project is not affected by `typesVersions`. For example, a `d.ts` file in the previous example containing `import * as foo from "./index"`will still map to `index.d.ts`, not`index.v3.d.ts`, whereas another package importing `import * as foo from "package-name"`_will_ get `index.v3.d.ts`.
128
+
请注意,重定向仅影响包的*外部*API;`typesVersions` 不会影响项目内的导入解析。例如,前面示例中包含 `import * as foo from "./index"`的 `d.ts` 文件仍将映射到`index.d.ts`,而另一个导入 `import * as foo from "package-name"`的包将获取 `index.v3.d.ts`。
142
129
143
-
## Matching behavior
130
+
## 匹配行为
144
131
145
-
The way that TypeScript decides on whether a version of the compiler & language matches is by using Node's [semver ranges](https://github.com/npm/node-semver#ranges).
`typesVersions`can support multiple fields where each field name is specified by the range to match on.
136
+
`typesVersions`可以支持多个字段,其中每个字段名称由要匹配的范围指定。
150
137
151
138
```json tsconfig
152
139
{
@@ -160,24 +147,21 @@ The way that TypeScript decides on whether a version of the compiler & language
160
147
}
161
148
```
162
149
163
-
Since ranges have the potential to overlap, determining which redirect applies is order-specific.
164
-
That means in the above example, even though both the `>=3.2` and the `>=3.1` matchers support TypeScript 3.2 and above, reversing the order could have different behavior, so the above sample would not be equivalent to the following.
Packages under the [@types](https://www.npmjs.com/~types) organization are published automatically from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) using the [types-publisher tool](https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/publisher).
182
-
To get your declarations published as an @types package, please submit a pull request to [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped).
183
-
You can find more details in the [contribution guidelines page](https://definitelytyped.github.io/guides/contributing.html).
0 commit comments