@typescript_ru

Страница 135 из 669
Dreamerinnoise
14.12.2016
14:39:21
https://www.typescriptlang.org/play/index.html#src=%0D%0Aclass%20Component%20%7B%0D%0A%20%20constructor%20(public%20name%3A%20string)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aclass%20Frame%20implements%20Iterable%3CComponent%3E%20%7B%0D%0A%20%20private%20pointer%20%3D%200%3B%0D%0A%0D%0A%20%20constructor(public%20name%3A%20string%2C%20public%20components%3A%20Component%5B%5D)%20%7B%7D%0D%0A%0D%0A%20%20public%20next()%3A%20IteratorResult%3CComponent%3E%20%7B%0D%0A%20%20%20%20if%20(this.pointer%20%3C%20this.components.length)%20%7B%0D%0A%20%20%20%20%20%20return%20%7B%0D%0A%20%20%20%20%20%20%20%20done%3A%20false%2C%0D%0A%20%20%20%20%20%20%20%20value%3A%20this.components%5Bthis.pointer%2B%2B%5D%0D%0A%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%20else%20%7B%0D%0A%20%20%20%20%20%20return%20%7B%0D%0A%20%20%20%20%20%20%20%20done%3A%20true%0D%0A%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%0D%0A%20%20%5BSymbol.iterator%5D()%3A%20IterableIterator%3CComponent%3E%20%7B%0D%0A%20%20%20%20return%20this%3B%0D%0A%20%20%7D%0D%0A%0D%0A%0D%0A%7D%0D%0A%0D%0Alet%20frame%20%3D%20new%20Frame(%22Door%22%2C%20%5Bnew%20Component(%22top%22)%2C%20new%20Component(%22bottom%22)%2C%20new%20Component(%22left%22)%2C%20new%20Component(%22right%22)%5D)%3B%0D%0Aconsole.log(frame.next().value)%3B%0D%0Aconsole.log(frame.next().value)%3B%0D%0Aconsole.log(frame.next().value)%3B%0D%0Aconsole.log(frame.next().value)%3B%0D%0A%0D%0Afor%20(let%20cmp%20of%20frame)%20%7B%0D%0A%20%20console.log(cmp)%3B%0D%0A%7D

вот тут я запутался

Это прям как по книжке

хотя может книжка дерьмо

Google
Aleh
14.12.2016
14:39:52
хотя может книжка дерьмо
for of только с массивами умеет

в ts

Dreamerinnoise
14.12.2016
14:51:51
Въехал. https://github.com/Microsoft/TypeScript/pull/12346 по идее должна закрыть это.

Aleh
14.12.2016
15:11:31
да

Vladimir
14.12.2016
18:11:40
А кто-нибудь встречал годный prod конфиг для TS+React?

Aleh
14.12.2016
18:23:15
{ "compilerOptions": { "jsx": "react" } }

:)

хотя для годности надо обязательно добавить noImplicitAny: true и strictNullChecks: true

Anatoly
14.12.2016
18:25:08
Я вот когда закончу с окончательным переездом на ES6 modules, тоже хочу noImplicitAny: true. Но пока, 537 <any> ?

Aleh
14.12.2016
18:26:15
а strictNullChecks уже есть? :)

Anatoly
14.12.2016
18:26:36
? А как думаешь? )

Aleh
14.12.2016
18:26:41
думаю нет)

Yuri
14.12.2016
18:51:59
расскажите как правильно сделать такое function myFunc(arg: string | Function) { if (typeof arg === 'function') arg() }

Google
Yuri
14.12.2016
18:52:36
сейчас такое говрит cannot invoke an expression whose type lacks a call signature.

Aleh
14.12.2016
18:54:44
расскажите как правильно сделать такое function myFunc(arg: string | Function) { if (typeof arg === 'function') arg() }
https://www.typescriptlang.org/play/index.html#src=function%20myFunc(arg%3A%20string%20%7C%20Function)%20%7B%0A%20%20%20%20if%20(typeof%20arg%20%3D%3D%3D%20'function')%0A%20%20%20%20%20%20%20%20arg()%0A%7D

может версия старая?

Yuri
14.12.2016
18:55:57
я тоже обратил внимание что в репле все ок

сейчас пытаюсь понять

Aleh
14.12.2016
18:57:12
так а какая версия ts?

Yuri
14.12.2016
18:58:31
вот так правильней

https://www.typescriptlang.org/play/index.html#src=function%20myFunc(arg%3A%20string%20%7C%20Function)%20%7B%0A%20%20%20%20if%20(typeof%20arg%20%3D%3D%3D%20'function')%0A%20%20%20%20%20%20%20%20arg()%0A%7D

блин

прости

function a(arg: string | string[] | Function = '') { switch (typeof arg) { case 'function': arg() } }

я не осилил получить там ссылку

при этом! если заменить case на if

все работает ок

Aleh
14.12.2016
19:02:07
хм

Yuri
14.12.2016
19:02:12
это я только что нашел

ебанутый язык, простите ))

о, теперь стал тоже if подсвечивать

вообщем вот function a(arg: string | string[] | Function = '') { if (typeof arg === 'funciton') arg() }

а это я там опечатался

Google
Yuri
14.12.2016
19:04:33
вот )) так нет ошибки function a(arg: string | string[] | Function = '') { if (typeof arg === 'function') arg() }

а так есть

function a(arg: string | string[] | Function = '') { switch (typeof arg) { case 'function': arg() } }

Aleh
14.12.2016
19:05:51
ну походу в switch case не умеет(

Yuri
14.12.2016
19:07:23
погоди

ты сейчас упадешь

а так опять ошибка

function a(arg: string | string[] | Function = '') { const typeofArg = typeof arg if (typeofArg === 'function') arg() }

пиздец просто сатанизм какой-то

Aleh
14.12.2016
19:09:12
switch case сломан

https://www.typescriptlang.org/play/index.html#src=function%20isFunction(f%3A%20any)%3A%20f%20is%20Function%20%7B%0A%20%20%20%20return%20typeof%20f%20%3D%3D%3D%20'function'%3B%0A%7D%0A%0Afunction%20a(arg%3A%20string%20%7C%20string%5B%5D%20%7C%20Function%20%3D%20'')%20%7B%0A%20%20%20%20switch%20(isFunction(arg))%20%7B%20%0A%20%20%20%20%20%20%20%20case%20true%3A%20arg()%3B%20%0A%20%20%20%20%7D%0A%7D

Yuri
14.12.2016
19:10:32
а сохраненное знаечение typeof тоже сломано?

Aleh
14.12.2016
19:11:00
да, думаю что его никогда не планировали и скорее всего не собираются

https://github.com/Microsoft/TypeScript/issues/8934

> Not a common enough pattern to support

https://github.com/Microsoft/TypeScript/issues/2214

кор тим делать не будет, если кто-то из коммунити очень хочет, то может запилить

Yuri
14.12.2016
19:26:15
facepalm

Aleh
15.12.2016
09:56:26
https://github.com/Microsoft/TypeScript/pull/12826 хм, этот фикс войдет в 2.1 или только в 2.2?

Vasiliy
15.12.2016
12:20:53
а как сделать children non-optional в ts? никак?

Google
Aleh
15.12.2016
12:21:23
Vasiliy
15.12.2016
12:22:05
interface ICellDescriptor { columnIndex: number; rowIndex: number; } type CellRenderer = (info: ICellDescriptor) => React.ReactNode; interface IGridSomethingProps { width: number; height: number; children: CellRenderer; }

<GridSomething width={columnWidth} height={rowHeight}> {this.renderLeftHeaderCell} </GridSometing>

Property 'children' is missing in type 'IntrinsicAttributes & IGridSometingCornerProps'.

:(

он все врет

Aleh
15.12.2016
12:23:39


Vasiliy
15.12.2016
12:26:08
воу, а как вы defaultProps определяете?

optional?

interface IMyTurboGridProps { columnWidth?: number; columnCount?: number; height?: number; overscanColumnCount?: number; overscanRowCount?: number; rowHeight?: number; rowCount?: number; }

Admin
ERROR: S client not available

Vasiliy
15.12.2016
12:26:44
и потом

public static defaultProps = { columnWidth: 50, columnCount: 50, height: 500, overscanColumnCount: 0, overscanRowCount: 5, rowHeight: 40, rowCount: 100, };

а то это странно

Aleh
15.12.2016
12:27:04
Ну так они ж по факту optional

Vasiliy
15.12.2016
12:27:22
да, для потребителя

Aleh
15.12.2016
12:27:48
Ага

Vasiliy
15.12.2016
12:27:54
а по факту приходится писать в render

что-то типа

Aleh
15.12.2016
12:28:08
Я понял, это проблема да

Google
Vasiliy
15.12.2016
12:28:08
={columnWidth as number}

я даже записывать их не успеваю

не то чтобы помогать их решать

:(

Aleh
15.12.2016
12:29:20
Вообще я не юзал defaultProps

Vasiliy
15.12.2016
12:29:44
иногда удобно определять поведение по умолчанию, пользотель компонента кинул его себе в проект и сразу видит результат и настраивает уже дальше в victory например похожие идеи

Aleh
15.12.2016
12:30:09
Наверное

Dreamerinnoise
15.12.2016
12:35:59
Vasiliy
15.12.2016
12:41:29
ну да, но это не удобно получается, не понятно как быть с тем, что они optional для потребителя и non-optional для внутренней реализации

ладно, я as mytype пишу, тк времени нет, а вообще это странно

Vladimir
15.12.2016
12:48:07
Для этого есть $Diff во Flow

Vasiliy
15.12.2016
12:52:43
кстати, а почему некоторые типы во флоу начинаются с символа $ ?

Aleh
15.12.2016
12:55:47
Это типа как внутренние хелперы

Dreamerinnoise
15.12.2016
12:55:56
Это не публичные хелперы

Aleh
15.12.2016
12:56:14
Вроде ни один из них нельзя заимплементить на самом flow

Vladimir
15.12.2016
12:57:36
Это само собой

Vasiliy
15.12.2016
12:57:51
я про то, что мб это нельзя юзать)

Vladimir
15.12.2016
12:57:58
Нет, можно

Vasiliy
15.12.2016
12:58:12
т.е. они не выпилят это внезапно когда-нибудь?

Vladimir
15.12.2016
12:58:24
Возможно, но страшного в этом мало

Aleh
15.12.2016
12:58:24
Вряд ли

Vladimir
15.12.2016
12:58:36
Всегда можно написать $Foo = any

И жить дальше

Страница 135 из 669