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

Add typings instructions from snippet users and export Snippet type #541

Merged
merged 2 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-falcons-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': minor
---

Export AnalyticsSnippet type and add directions (for snippet users).
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,41 @@ export default defineComponent({
</script>
```



### For snippet users only: How to add typescript support

1. Install npm package `@segment/analytics-next`

2. Create `./typings/analytics.d.ts`
```ts
// ./typings/analytics.d.ts
import type { AnalyticsSnippet } from "@segment/analytics-next";

declare global {
interface Window {
analytics: AnalyticsSnippet;
}
}

```
3. Configure typescript to read from the custom `./typings` folder
```jsonc
// tsconfig.json
{
...
"compilerOptions": {
....
"typeRoots": [
"./node_modules/@types",
"./typings"
]
}
....
}
```


# 🐒 Development

First, clone the repo and then startup our local dev environment:
Expand Down
35 changes: 35 additions & 0 deletions packages/browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,41 @@ export default defineComponent({
</script>
```



### For snippet users only: How to add typescript support

1. Install npm package `@segment/analytics-next`

2. Create `./typings/analytics.d.ts`
```ts
// ./typings/analytics.d.ts
import type { AnalyticsSnippet } from "@segment/analytics-next";

declare global {
interface Window {
analytics: AnalyticsSnippet;
}
}

```
3. Configure typescript to read from the custom `./typings` folder
```jsonc
// tsconfig.json
{
...
"compilerOptions": {
....
"typeRoots": [
"./node_modules/@types",
"./typings"
]
}
....
}
```


# 🐒 Development

First, clone the repo and then startup our local dev environment:
Expand Down
2 changes: 2 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export * from './core/context'
export * from './core/events'
export * from './core/plugin'
export * from './core/user'

export type { AnalyticsSnippet } from './browser/standalone-analytics'