-
Notifications
You must be signed in to change notification settings - Fork 6
feat(typings): allow to get component info separate to typings #9
Conversation
@@ -1,7 +1,8 @@ | |||
/* eslint no-use-before-define: ["error", "nofunc"] */ | |||
const upperCamelCase = require('uppercamelcase'); | |||
|
|||
function stringifyType(type) { | |||
function stringifyType(type, componentName, name, typesRef) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Еще есть изменения в генерации тайпингов. Теперь вложенные сложные типы тоже будут экспортиться, так их проще использовать. Пример сгенерированного d.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем их экспортить? На мой взгляд - лучше не давать пользователь возможность завязваться на интерфейсы библиотеки. В каком кейсе это необходимо?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В процессе перетягивания депозитов на это наткнулся. Например для создания меню мы используем <Menu content={ content } />
content
создается руками, это массив.
content = [ { type: 'item', content: 'foo' }, ... ]
Если использовать это прям так - ts ругается что тип string (который он выводит для поля type
) не равен типу 'item' | 'group'
, который у нас указан для поля type. И тут остается только два выбора - ставить any либо ручками прописывать тайпинг. Оба варианта вообще не удобны.
Ну и такие кейсы есть и в других местах, типа создания компонентов поверх физеровских и т.д.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function t(params: Array<{ type?: 'input' | 'button' }>) {
}
const params = [{ type: 'input' }];
t(params)
Если вставишь туда - увидишь ругань
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я думал что для const Array тоже уже сделали microsoft/TypeScript#10676
Значит до сих пор отстой
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Значит твое предложение действительно актуально
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну помимо этого еще есть кейс с компонентами, переиспользующими типы. Например CorporateAccountSelect, у которого есть поле otherOptions, которое должно быть точно таким же как и options у Select (конечно для этого конкретного примера это не актуально, но это просто чтоб мысль донести)
react-doc/docgen/is-cn-component.js
Outdated
@@ -0,0 +1,10 @@ | |||
function isCnOverrideComponent(path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDecoratedBy(path, 'cn')?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
import { Component, ReactNode } from 'react'; | ||
|
||
export interface ${componentName}Props { | ||
export interface ${info.displayName}Props { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const propsInterfaceName = ${info.displayName}Props
;
...
export default class ${info.displayName} extends Component<${propsInterfaceName}, any> {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
|
||
function stringifyComponentDefinition(info) { | ||
const types = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно как-то переименовать чтоб было понятно что такое types, typesRef что-тотипа globalTypes
или хотябы комменты какие-то
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
}`; | ||
} | ||
|
||
function stringifyObjectOf(type) { | ||
function stringifyObjectOf(type, componentName, name, typesRef) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name - путает - что это за нэйм?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
…rt cn extended components
support cn extended components