Repository navigation
Establish pattern for typing legacy plugins - #26045
Conversation
|
Pinging @elastic/kibana-platform |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1809352 to
c487338
Compare
This comment has been minimized.
This comment has been minimized.
c487338 to
2027e52
Compare
This comment has been minimized.
This comment has been minimized.
2027e52 to
8d4bcf9
Compare
This comment has been minimized.
This comment has been minimized.
8d4bcf9 to
2084871
Compare
This comment has been minimized.
This comment has been minimized.
2084871 to
f28fe2c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
801ef3d to
1ed19c6
Compare
This comment has been minimized.
This comment has been minimized.
1ed19c6 to
6854250
Compare
This comment has been minimized.
This comment has been minimized.
33d19ca to
6dbf52b
Compare
This comment has been minimized.
This comment has been minimized.
6dbf52b to
6276d7c
Compare
This comment has been minimized.
This comment has been minimized.
|
Any idea on the ETA of this PR? I'd like to use |
There was a problem hiding this comment.
There is a top level typings folder too, I think types is new in this PR? I think this will end up being confusing. Maybe they can be merged?
There was a problem hiding this comment.
hm, no there isn't, so actually types folder must be a build artifact, hence the gitignore? Still a bit confusing then I think... but I also am not fully aware of everything that is going on with the types setup, and that typings folder is pretty new so maybe there was just a disconnect.
There was a problem hiding this comment.
The types directory is built from yarn build:types which gets run on yarn kbn bootstrap. In master it goes to the target/types directory but in this PR I changed it to types.
The reason I changed it to not be target is that the build wipes out that directory before building and I was previously trying to import from it which was failing Typescript build for x-pack. Let me confirm, but I think after some of the other changes I made, I can put this back the way it was before.
There was a problem hiding this comment.
Confirmed, I'll put this back to pulling from the target directory to reduce confusion. Thanks for catching this!
6ec245b to
6c50de9
Compare
This comment has been minimized.
This comment has been minimized.
6c50de9 to
1a7b47c
Compare
💔 Build Failed |
sorenlouv
left a comment
There was a problem hiding this comment.
Changes to APM look good 👍
|
Why import type information differently depending on whether the plugin is internal or not? |
| /** | ||
| * All exports from TS source files (where the implementation is actualy done in TS). | ||
| */ | ||
| export * from './target/types/type_exports'; |
There was a problem hiding this comment.
question: btw, I just realized that we may need to add one more Project to src/dev/build/tasks/transpile_typescript_task.js with tsconfig.types.json and run it as the first one, so that plugins that depend on generated types can be successfully built/transpiled during build? We have just one now, src/plugins/test, but it's excluded from build. It's semi out-of-scope for this PR so feel free to ignore that :)
There was a problem hiding this comment.
Ok, I've updated the build to build this project, but in the repo root rather than the build root. The reason for this is we build the typescript files from the repo root in x-pack so the types will need to be present there. I've also added an alias so you can now do this in any x-pack code:
import { Legacy } from 'kibana'| @@ -0,0 +1,391 @@ | |||
| /* | |||
There was a problem hiding this comment.
question: is this file crafted by you or we have copied it from somewhere? Just checking whether I should review it or not :)
There was a problem hiding this comment.
It's written by me. Due to the way we use strings in callWithRequest to lookup methods on the elasticsearch.js Client I had to write all of those method calls with the appropriate params and return types from '@types/elasticsearch'
| import { ElasticsearchPlugin } from '../legacy/core_plugins/elasticsearch'; | ||
|
|
||
| export interface KibanaConfig { | ||
| get<T = any>(key: string): T; |
There was a problem hiding this comment.
question: should it rather be T = unknown?
|
|
||
| import { GraphQLSchema } from 'graphql'; | ||
| import { Request, ResponseToolkit, Server } from 'hapi'; | ||
| import { Request, ResponseToolkit, Server } from 'src/server/kbn_server'; |
There was a problem hiding this comment.
question: why can't we use relative paths here and point to the root index.d.ts with Legacy namespace?
There was a problem hiding this comment.
See comment above, you can now do import { Legacy } from 'kibana'
f570c66 to
3a9239e
Compare
|
@epixa I've changed the build process so now they can all import the same way, directly from |
💔 Build Failed |
|
retest |
💚 Build Succeeded |
azasypkin
left a comment
There was a problem hiding this comment.
The overall shape of this PR and the part related to the new platform look good to me, thanks! The only part I haven't looked closely at is the the Elasticsearch client types, but we can improve them along the way if/when needed.
| @@ -0,0 +1,48 @@ | |||
| /* | |||
There was a problem hiding this comment.
question: just curious, why not index.d.ts as it was before? I believe there is even a convention to rely on index.d.ts from the project root if types isn't specified in package.json (not that we shouldn't set it explicitly, but still).
There was a problem hiding this comment.
TypeScript compiler doesn't support using the compilerOptions.paths feature to reference the index.d.ts file, but it works when using a different name. Using this option was necessary to support import ... from 'kibana' for x-pack and core packages.
💚 Build Succeeded |
* Add legacy types and export them for plugins * Add support for core_plugins to import from 'kibana'
|
6.x: 16a900a |
* Add legacy types and export them for plugins * Add support for core_plugins to import from 'kibana'
Summary
This adds a new common pattern for adding type definitions to legacy plugins and the KbnServer itself.
Now plugins that wish to use TypeScript can import our customized Server type from
src/server/kbn_serverto get a type that has definitions supplied for each of the objects onserver.plugins(eventually).Plugins (core_plugins, x-pack, and external) will be able to use our exported types by importing the Legacy namespace: