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

The initialization order of the Class Accessor Decorator has been changed. #57844

Closed
examan opened this issue Mar 19, 2024 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@examan
Copy link

examan commented Mar 19, 2024

πŸ”Ž Search Terms

Class Accessor Decorator init addInitializer

πŸ•— Version & Regression Information

  • This changed between versions 5.3.3 and 5.4.2

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.2#code/GYVwdgxgLglg9mABAEwDwDUCGAbEBTAGkQBUALGAZ0QF5FwBrMOAdzAD4AKASkQG8AoREMQAnPFBAikHQcLkB9AG458ALkQBhbJgoUAghAh5dcEQBE8EU5iinimEQHNxqMpSJZceNgVlyhVmBQeAAeUOpaOvqGxhSmFlYiNqYaCMFhruQUHirevnI81Gx8fv7Y4oiK6p74ANylcoHpUAB0mMjIAJJgMLA4MABeeCIc3DTFAv5TiIFx5S3YcI4cAOTtXT192IPDK1z104gAvvv8DcJiElIlh3LOUGOTt1OXkkiKB8-H+V8U4hzKLw8J5fYSKGiVXKfZ5HH7PGCbAG5YHnZ6zODzRbLFYI3p7aGgyoQwF1VG3V7XEl4AmHWFko6ICg2SjAGDGTTaXQGIwmcyWay2EQAJWMIGwUEy7kQNW8BKO9SOZwgnKoxGMUBuwgAAshuKVMDFeYhgBDgDg-gqlQgKBrgjaIWA8MwSOruLUgA

πŸ’» Code

function d<Value, This = unknown>() {
    return (
        _value: ClassAccessorDecoratorTarget<This, Value>,
        context: ClassAccessorDecoratorContext<This, Value>,
    ) => {
        let v: Value;
        context.addInitializer(() => {
            console.log('addInitializer');
        });

        return {
            get() {
                return v;
            },
            set(value) {
                v = value;
            },
            init(value) {
                console.log('init');
                v = value;
                return value;
            },
        } satisfies ClassAccessorDecoratorResult<This, Value>;
    };
}

class Test {
    @d()
    accessor f = false;
}

const test = new Test();

πŸ™ Actual behavior

console.log order:
init
addInitializer

πŸ™‚ Expected behavior

console.log order:
addInitializer
init

Additional information about the issue

No response

@jakebailey
Copy link
Member

I think this was intentional? #56606 #56955

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 19, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants