Giter Club home page Giter Club logo

Comments (4)

devpaul avatar devpaul commented on July 22, 2024 3

Yeah, the pattern used with DeclareConstructor makes this a sticky issue to resolve.

It's usage should be OK with declare, but I was trying to extend Evented like a class

export default class<T> extends Evented implements StateMachineEvents<T> {

Which results in the error

error TS2510: Base constructors must all have the same return type.

The error may be due to Evented having two different constructors:

interface EventedConstructor extends _base.DeclareConstructor<Evented> {
	new (params?: Object): Evented;
}

interface DeclareConstructor<T> {
	new (...args: any[]): T & DeclareCreatedObject;

I was able to resolve by "fixing" the typings

export interface FixedEventedConstructor {
	new (params?: Object): dojo.Evented;
}
export const FixedEvented: FixedEventedConstructor = <any> Evented;

I haven't had a chance to play with TypeScript 2.2. Hopefully we'll be able to define mixin classes as purely ambient declarations that return functional constructors. If we have to apply it as a pattern in code and actually have to return a class that extends from a declare statement, I would be concerned about losing the metadata added by declare to allow for functional chaining via inherited. Hopefully it'll be the former and we'll have a good way of declaring define.

Anyway, all of this created a rabbit hole I knew I didn't want to go down on my own.

from typings.

dylans avatar dylans commented on July 22, 2024

@mmckenziedev have you run into an issue with this yet?

from typings.

mmckenziedev avatar mmckenziedev commented on July 22, 2024

@dylans I haven't had problems using Declare to mix this in to other classes.

I agree that technically this class is an ES5 class and shouldn't use DeclareConstructor. However, in practice, if you're using Declare to create a new class and you try to mix this in, if it is not a DeclareConstructor then it won't work properly due to the way Declare is defined.
_base.d.ts#L620

If it's not breaking anything I would prefer to leave this as it is for now. When Typescript 2.2 comes out, and we can finally have a better expression syntax for mixins, then we could refactor the way Declare works.

https://github.com/Microsoft/TypeScript/wiki/Roadmap#22-february-2017
microsoft/TypeScript#13743

from typings.

schontz avatar schontz commented on July 22, 2024

This issue bit me as well. Is #113 (comment) the prescribed way around it for now?

from typings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.